regexp = new RegExp(\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b);
Error:66SyntaxError: Unrecognized token '\'
-
You should also see: stackoverflow.com/questions/2966535/… if you are using word boundaries.user1282358– user12823582012-03-21 02:28:34 +00:00Commented Mar 21, 2012 at 2:28
Add a comment
|
2 Answers
When calling new RegExp() you must pass the pattern as a string. Enclose it in quotes.
var regexp = new RegExp('\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b');
You could also create it as using the special /pattern/ delimited syntax, in which it is not quoted:
var regexp = /[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}/;