This regex isn’t valid in JavaScript. It says there is an invalid group. Can someone help me make it work?
(?i)^(?![\. -])(?!.*[\. -]$)[\w!$%'*+/=?^`{|\.}~ -]{1,64}$
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Update: Updating as per suggestions given in comments.
Use one of these three expressions instead. It is the same regex, just fixing the
(?i)part and adding required escaping to match Javascript specifications.If you are using
new RegExpto construct your regex object, then you have to escape all your backslashes. The difference between first and second expression is that the second one is using single quotes to construct the regex string and there is a single quote as part of your regex, so you have to escape the single quote to make it work properly. The third expression uses the/pattern/flagssyntax to construct the regex object. As pointed by Mike in comments, you have to escape/if it is not inside a character set. All your/s are inside character sets, so no escaping is necessary.Check out more on javascript regex syntax here https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp