0

I'm trying to use Regex.Match to match something, but it already has quotes in it, and it cancels the Regex.Match's quotes. I have checked other threads but their answers didn't work for me.

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

Just in case. The HTML code from the website is this:<span style="font-size: 18px; color: #6C0; height: 28px; text-shadow: 0 0 1px #000;">[What I want is here]</span>

Mohanad
  • 165
  • 1
  • 1
  • 12
  • If you really checked other threads, you'd know that [parsing html with regex is a really bad idea](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) Use an html parser. HtmlAgilityPack is great. – spender Jun 21 '14 at 10:49
  • I actually really did check other threads and decided that using something other than HtmlAgilityPack is easier for me. I have tried though.. Just personal preference. – Mohanad Jun 21 '14 at 11:03

1 Answers1

1

You need to escape your quotes. In string literals, use \" (e.g. "My name is \"Bob\"."). In verbatim string literals, use "" (e.g. @"My name is ""Bob""."). See 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>");
Douglas
  • 53,759
  • 13
  • 140
  • 188