1
regexp = new RegExp(\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b);

Error:66SyntaxError: Unrecognized token '\'
1

2 Answers 2

5

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}/;
Sign up to request clarification or add additional context in comments.

Comments

0

I think the regex should be:

/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.