Reputation: 13
I want to extract the values between TDs from this piece of text (html markup).
<tr id="pair_169">
<td id="cr_12cl_last169">16,294.61</td>
<td>16,294.61</td><td>16,318.11</td>
<td class="">16,225.25</td>
<td class="bold greenFont">73.47</td>
<td class="bold greenFont">0.45%</td>
<td id="cr_12cl_date169">23/12</td>
</tr>
what would be the best Regex pattern?
Upvotes: 1
Views: 5535
Reputation: 661
I know this is a old thread but this one helped me for similar situation
<td\b[^>]class=".*?>(.*?)<\/td>
Upvotes: 1
Reputation: 28403
Try this regex
<td>(.*?)</td>
Or this, but it is used to match exactly TD only with TR
(?<1><TR[^>]*>\s*<td.*?</tr>)
Upvotes: 1
Reputation: 1979
You can use the following code:
const string pattern = @"<td\b[^>]*?>(?<V>[\s\S]*?)</\s*td>";
foreach (Match match in Regex.Matches(inputText, pattern, RegexOptions.IgnoreCase))
{
string value = match.Groups["V"].Value;
Console.WriteLine(value);
}
Upvotes: 1