I'm trying to make regex which will match all console.log("anything"); in the file. I wrote next pattern string:
@"(console\.log\(\"(.*)\"\)\;)"
The compiler doesn't compile code and says:
Method, Delegate or event is expected.
The problem is with stripslashing - " characters. But I don't know how to fix it, any ideas?
I use this pattern in method:
js.RegexReplace(@"(console\.log\(\"(.*)\"\)\;)", "", RegexOptions.Singleline);
js is a string variable.
RegexReplace signature:
string RegexReplace(this string input, string pattern, string replacement, RegexOptions options)
You are mixing the verbatim and the escape character. That is not working as you expect, since you can't use \ to escape ", but need to use ".
Use this string with the verbatim:
@"(console\.log\(""(.*)""\)\;)"
Use this string, without the verbatim:
"(console\\.log\\(\"(.*)\"\\)\\;)"
Double double quotation marks:
@"(console\.log\(""(.*)""\);)"
EDIT:
You do not have to escape ""s when using verbatim strings.
So, the C# code will look like:
var pattern = @"(console\.log\(""(.*)""\);)";
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