java - Grep character sequence -
i need match character sequences of form abcd12345 , others of form abcd54321.aaa.
i have written code check both forms, works correctly input sequence abcd12345 because abcd54321.aaa matched both regex's (the 1 abcd54321.aaa , 1 abcd54321).
how modify regular expression(s) 1 of them matches when input abcd54321.aaa?
here snippet of java code shows patterns using match character sequences:
string[] patternvalues = new string[] { "[aa.][bb][cc][dd]\\d+\\.+[a-za-z]{3}","[aa.][bb][cc][dd]\\d+"} ; for(int = 0 ; <= (patternvalues.length - 1) ; i++) { pattern regexp = pattern.compile(patternvalues[i]); ..... }
you want regular expression abcd54321-only match:
abcd54321(?!\.aaa) that match abcd54321 not followed .aaa.
if want case-insensitive, first prepare pattern.compile() using case_insensitive flag:
pattern.compile("abcd54321(?!\\.aaa)", pattern.case_insensitive);
Comments
Post a Comment