Skip to content Skip to sidebar Skip to footer

Regexp Special Characters Escape

I have messed around with special characters in regular expression for several hours now, and must admit that i give up. Trying to make a password test function, that test for at l

Solution 1:

The reason is - has special meaning in character class. So \+-£ inside it means "all characters in table of Unicode codes from '+' up to '£'".

So you need escape '-' there.

And yes, you don't need to escape all other characters there

/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[¤@+\-£$!%*#?&().:;,_]).{8,}$/g

should be fine for you

Solution 2:

enough you add "\" before "+" and "-";

 var Regex1 =^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[¤@\+\-\£\$\!%\*#\?&\(\)\.\:;,_]).{8,}$

easy way for test your regular expressions is use this website: https://regex101.com/

this example is also good:

Use RegEx To Test Password Strength In JavaScript

var mediumRegex = newRegExp("^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})");

https://www.thepolyglotdeveloper.com/2015/05/use-regex-to-test-password-strength-in-javascript/

Post a Comment for "Regexp Special Characters Escape"