I need to match these characters. This quote is from an API documentation (external to our company):
Valid characters: 0-9 A-Z a-z & # – . , ( ) / : ; ‘ @ “
I used this Regex to match characters:
^[0-9a-z&#-\.,()/:;'""@]*$
However, this wrongly matches characters like %, $, and many other characters. What’s wrong?
You can test this regular expression online using http://regexhero.net/tester/, and this regular expression is meant to work in both .NET and JavaScript.
You are not escaping the dash
-, which is a reserved character. If you add replace the dash with\-then the regex no longer matches those characters between#and\