C#引用引号(Regex Matching)

时间:2014-06-21 10:44:43

标签: c# html css regex string-matching

我尝试使用Regex.Match来匹配某些内容,但它已经包含引号,并取消了Regex.Match的引号。 我检查过其他帖子,但他们的答案对我没用。

Match divisionWinsLosses = Regex.Match(website, @"<span style="font-size: 18px; color: #6C0; height: 28px; text-shadow: 0 0 1px #000;">(.*?)</span>");

以防万一。网站上的HTML代码为:<span style="font-size: 18px; color: #6C0; height: 28px; text-shadow: 0 0 1px #000;">[What I want is here]</span>

1 个答案:

答案 0 :(得分:1)

你需要逃避你的报价。在字符串文字中,使用\"(例如"My name is \"Bob\".")。在逐字字符串文字中,使用""(例如@"My name is ""Bob"".")。请参阅Strings (C# Programming Guide)

Match divisionWinsLosses = Regex.Match(website, @"<span style=""font-size: 18px; color: #6C0; height: 28px; text-shadow: 0 0 1px #000;"">(.*?)</span>");