Reputation: 471
I am required to fetch all SPAN tags with CLASS CLASSIFY. In one of the case, the RegEx which I am using is skipping the First SPAN tag.
RegEx
<span [^>]*class=\"classify\"(.*?)</span>
C# Code
Regex.Matches(content, "<span [^>]*class=\"classify\"(.*?)</span>", RegexOptions.Multiline)
Content:
<span categoryid="110" categorytext="(Sup ed (Inl))" class="classify" classifyid="3395349" quoteid="" quotetext="" selectedclassify="true" style="font-weight: bold; background-color: #ffa500">
<u>Objective/reason for interaction</u>
<br /> wtwt
<br />
<br /> <u>Summary</u><br /> As -16/08/15</span>
<br />
<br />
<u>Actions</u>
<br /> N
<br />
<br />
<u>Outcomes/reportables</u>
<br />
<span categorytext="(Nofrf of J Ced)" class="classify" quoteid="" quotetext="" selectedclassify="false" style="categoryid="13416"">1 full </span>
<br /> A Mag
<br />
<br />
<u>K</u>
<br /> As ab
<br />
Link to .Net RegEx tester:
Please advice, what I am missing in the RegEx.
Upvotes: 0
Views: 2044
Reputation: 1461
It's because the dot doesn't match new lines by default. You can use [\s\S] instead:
<span [^>]*class=\"classify\"([\s\S]*?)</span>
Or you can use your original pattern and set the Singleline option in RegexOptions.
Upvotes: 2