Search code examples
c#regexstringmultiple-matches

How to get each tablerow in regex from a string (C#)?


Basically, I've got a string like this:

<table><tr class="even"><td></td><td></td></tr><tr class="odd"><td></td><td></td></tr></table> 

I want to get each tablerow using Regex.Matches (c#)

What would my regex pattern be?

I've tried the following but I think it's probably pretty wrong:

"<tr"(.*)"</tr>" 
[<][t][r](.*)[<][/][t][r][>]" 

But even

[t][r].*[t][r]

Gives 0 matches.

Any idea?

Thanks a lot!


Solution

  • \<tr[\s\S]*?\/tr\>
    

    .?* : All Characters, stop at first match.

    \s\S : All Characters, even new lines.

    I use RAD Software Regular Expression Designer to create and test REGEX expressions. It is a great tool!