I'm writing a simple regex in c# to locate backslashes not preceded or followed by any backslashes:
Regex reg = new Regex(".*(?<!\\)\\(?!\\).*");
However, this statment generates an ArgumentException: "parsing ".(?" - Not enough )'s"
The group parentheses seem to match. Can anyone spot the problem?
Put the @ symbol in front of your string, otherwise you need to double-escape the slashes (once for C#, and once for Regex).
Regex reg = new Regex(@".*(?<!\\)\\(?!\\).*");
or
Regex reg = new Regex(".*(?<!\\\\)\\\\(?!\\\\).*");
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