Can't escape the backslash with regex?

Viewed 293776

I'm using the following regex

^[a-zA-Z0-9\',!;\?\$\^:\\\/`\|~&\" @#%\*\{}\(\)_\+\.\s=-]{1,1000}$

I know it's ugly, but so far it serves its purpose other than the backslash not being allowed as I think it should because it's escaped, I also tried \\ instead of \\\ but same results. Any ideas?

7 Answers

you can use ? at the end to skip one "\"

regex("\\\\?")

in some cases, it's possible to use . instead of \ and avoid escaping the backslash

Related