string aniPattern=@"(?si:<option value=\\\"(?<year>.*?)\\)";
这会中断,因为 " 在中间。但我需要它,因为我在正则表达式中使用它。
我尝试使用string aniPattern="(?si:<option value=\\\"(?<year>.*?)\\\\)";
(不带@),但它不是有效的正则表达式。
important - it isn't entirely clear what you want to match; I've answered on the premise that only the "
is being a problem - but see also Mike Caron's answer which assumes everything is escaped incorrectly.
With a verbatim string literal (i.e. @"..."
), "
is escaped to ""
- so your string becomes:
string aniPattern=@"(?si:<option value=\\\""(?<year>.*?)\\)";
With a regular string literal (without the leading @
), you would need a lot worse:
string aniPattern="(?si:<option value=\\\\\\\"(?<year>.*?)\\\\)";
string aniPattern=@"(?si:<option value=""(?<year>.*?)\)";
For @ escaped strings, you double the quotation mark to escape it, since backslash is not used.
Use two double quotes next to each other, like so: ""