tags:

views:

32

answers:

2

Hello, I need to find anything inside a tr...

<tr class="class1">
    more tags here,
    multiple lines...
</tr>

How can I get anything that's between <tr class="class1"> and </tr>?

thanks!

+1  A: 

You need to use a real HTML parser, regex isn't sufficient to perform this task.

That said, you can use a poor expression like this: /<tr.*?>(.*?)<\/tr>/ where group 1 will have what's (generally) between the <tr> tags, but no guarantees on correctness...things like nested tags will throw this off. You need to use a real HTML parser.

Mark E
I just need to get what's between the trs... doesn't matter if it's well formed or not, and what it is inside
開発者
It does matter if it's well-formed or not, because if you were to create a regex, you'd have to take that into account. Also there could be infinite nesting of `<tr>`s, and regexes are not recursive. HTML parsers are the way to go.
Daniel Vandersluis
thanks, but nothing is matched... I'm using .net, any special settings should be set?
開発者
@開発者: see the corrected expression the `/` in `</tr>` had to be escaped. as far as I know there are no special settings required. You may not need the preceding `/` or trailing `/`.
Mark E
You do need to drop the `/` for a .NET regex (`@"<tr.*?>(.*?)</tr>"`) and to set `RegexOptions.Singleline` to allow the dot to match newlines. Other than that, what @Daniel Vandersluis said...
Tim Pietzcker
A: 

2 possibilites:

Client side: Jquery - http://docs.jquery.com/How_jQuery_Works

Server side: Linq To Xml - http://msdn.microsoft.com/en-us/library/bb387061.aspx

Examples can be added if needed. I however think that the articles I posted will be quite useful in getting you started.

diamandiev