Kamran1358
Kamran1358

Reputation: 13

Regex for extracting TD content

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

Answers (3)

Rushabh
Rushabh

Reputation: 661

I know this is a old thread but this one helped me for similar situation

<td\b[^>]class=".*?>(.*?)<\/td>

Upvotes: 1

Vignesh Kumar A
Vignesh Kumar A

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

Usman Zafar
Usman Zafar

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

Related Questions