I'm stuck with a regular expression problem.
I've got a string which I need to match. The string always starts with 2 letters, and then is followed by a 6 digit number, e.g.
- EF123456
- AB123456
However, there is one combination of letters which I need to ignore. e.g.:
- XX123456
So I want to write a regular expression to match only the normal format of the strings.
At the moment, I'm having to do:
Pattern pattern = Pattern.compile("[A-Z]{2}[0-9]{6}");
...
if(pattern.matcher(n).matches() && !n.toUpperCase().startsWith("XX")) {
// do match stuff
}
How can I rewrite my regexp so that I can get rid of the startsWith clause in my code above?