Using following regexp I can get if a string starts with a or b.
Pattern p = Pattern.compile("^(a|b)");
Matcher m = p.matcher("0I am a string");
boolean b = m.find();
System.out.println("....output..."+b);
But I need to check if the string starts with some special characters like * or ^ etc. In that case the following regexp gives Pattern error.
Pattern p = Pattern.compile("^(*|^)");
Matcher m = p.matcher("0I am a string");
boolean b = m.find();
System.out.println("....output..."+b);
How to check if a number starts with * or ^ using regular expression
Thanks to mathematical.coffee for nice response
Finally I found a solution by using
^[*^]as regexp to test whether a string contains*or^Source Code