I am having trouble compiling a regex. I cant find what the problem is with this expression as I got it from Cisco documentation and I don't understand why it does not work. I'm hoping that somebody could tell me what is wrong with it. This is what I am trying to do:
public void test(){
try{
pattern.compile("^[]0-9*#X[^-]{1,50}$");
System.out.println("Syntax is ok");
} catch (PatternSyntaxException e) {
System.out.println(e.getDescription());
}
}
[]
. Are you wanting to search for those literal characters? I.e. an open square bracket and a close square bracket? If so, you'll need to escape them:\\[\\]
.