I am trying to match quotes using regex but I don't manage to escape them in the @string
- I am getting an error:
output = Regex.Replace(str, @"[\d-']", string.Empty); // valid
output = Regex.Replace(str, @"[\d-'\"]", string.Empty); // not valid!
This one is also does not work:
string str = "[\d-'\"]" // bad compile constant value!
To escape a "
in an a verbatim string, use ""
:
Regex.Replace(str, @"[\d-'""]", string.Empty);
The @
token suppresses \
escaping. If you remove the @
token it will work as expected, but you would have to escape the first backslash, i.e. "[\\d-'\"]"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With