Search code examples
c#regexregular-language

Why This expression accepting & symbol


I have this regex expression but it accepting & symbol.

string REGEX_ALPHANUMERIC_UNDERSCORE_NOSPACE = "^[a-zA-Z0-9_-,!.]+$";

I am not getting why it is accepting & symbol. Please help anyone Thanks


Solution

  • Try like this

    string REGEX_ALPHANUMERIC_UNDERSCORE_NOSPACE = "^[a-zA-Z0-9_\\-,!.]+$";