Dinesh M
Dinesh M

Reputation: 1086

JSLint - Unexpected '\' before '.'

I am getting the following warning in JSLint for my regex expression.

enter image description here

Unexpected '\' before '.'.
var regexForEmail = /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;

Can someone help me how to fix it or is there any other way to suppress the warning?

Thanks in advance

Dinesh.

Upvotes: 1

Views: 957

Answers (1)

Barmar
Barmar

Reputation: 780724

. doesn't have special meaning when it's inside square brackets, so there's no need to escape it there. " has no special meaning at all in regular expressions, so you never need to escape it.

var regexForEmail = /^(([^<>()\[\].,;:\s@"]+(\.[^<>()\[\].,;:\s@"]+)*)|(".+"))@(([^<>()\[\].,;:\s@"]+\.)+[^<>()\[\].,;:\s@"]{2,})$/i;

The only characters that are special inside square brackets are backslash, hyphen, right square bracket, and caret at the beginning.

See What special characters must be escaped in regular expressions?

Upvotes: 4

Related Questions