Does the System.Text.RegularExpressions namespace offer me anything to discover whether an input string has (“abc[0-9]” or “^aeiou$”) or has not (“abc123”) metacharacters? Or do I have to check manually for non-escaped characters in a certain list?
Does the System.Text.RegularExpressions namespace offer me anything to discover whether an input string has
Share
You have at least three options:
Use Regex.Escape and compare the result:
Apply Regex.Escape to each character to see if the escaped value is different:
Create your own based on the fact that the metachars shouldn’t change:
The third approach offers more control depending on the RegexOptions you use in your Regex. For example, if you’ll never use RegexOptions.IgnorePatternWhitespace, you can remove space as a metachar.