AaBa
AaBa

Reputation: 471

RegEx in C# to get all SPAN tags with a specific Class name

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 />  &nbsp;
<br />  <u>Summary</u><br />  As  -16/08/15</span>
<br />  &nbsp;
<br />  
<u>Actions</u>
<br />  N
<br />  &nbsp;
<br />  
<u>Outcomes/reportables</u>
<br />  
<span categorytext="(Nofrf of J Ced)" class="classify" quoteid="" quotetext="" selectedclassify="false" style="categoryid=&quot;13416&quot;">1 full </span>
<br />  A Mag
<br />  &nbsp;
<br />  
<u>K</u>
<br />  As ab
<br />  

Link to .Net RegEx tester:

Sample

Please advice, what I am missing in the RegEx.

Upvotes: 0

Views: 2044

Answers (1)

Kevin Collins
Kevin Collins

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.

Regex Tester link

Upvotes: 2

Related Questions