I have following regex pattern working fine in Javascript :
Pattern-
/\<span\>(\d{2}-\d{2}-\d{4})\s*?(\d{1,2}:\d{2}\s*?(?:am|pm))\s*?(?:<\/SPAN><BR\/?><SPAN>)?\s*?((\d[ -]*?){13,17})\s*?\<\/span\>/i
String -
<SPAN>06-24-2015 11:28AM 0250 01 90775 05342</SPAN>
But I am getting an error when passing same pattern string to Pattern.compile() function .
Error is : Invalid escape sequence .
Here is what I tried :
Pattern p = Pattern.compile("/\<span\>(\d{2}-\d{2}-\d{4})\s*?(\d{1,2}:\d{2}\s*?(?:am|pm))\s*?(?:<\/SPAN><BR\/?><SPAN>)?\s*?((\d[ -]*?){13,17})\s*?\<\/span\>/i ");
Matcher m = p.matcher("<SPAN>06-24-2015 11:28AM 0250 01 90775 05342</SPAN>");
boolean b = m.matches();
Please suggest how can i correct this .
Thanks
Edit
I changed my code to following after knowing comments, but now I cannot match the pattern:
Pattern p = Pattern.compile(
"(?i)/\\<span\\>(\\d{2}-\\d{2}-\\d{4})\\s*?(\\d{1,2}:\\d{2}\\s*?(?:am|pm))\\s*?(?:<\\/SPAN><BR\\/?><SPAN>)?\\s*?((\\d[ -]*?){13,17})\\s*?\\<\\/span\\>");
Matcher m = p.matcher("<SPAN>06-24-2015 11:28AM 0250 01 90775 05342</SPAN>");
boolean b = m.matches();
System.out.println("Do regex pattern matches : " + b);
/at the start with(?i)and remove/iat the end. The rest is up to you to check. And avoid escaping/- it is not a special regex metacharacter.\\dinstead of\d./after(?i). Do not escape/,<and>.