Reputation: 329
I have a problem with my regular expression. My data look like this:
<tr class="abcData"><td>Text Number One</td><td>text</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr class="abcData"><td>Text Number Two</td><td>text</td><td><span class="value">3</span></td><td><span class="value">3</span></td><td> </td><td> </td><td> </td><td> </td></tr>
<tr class="abcData"><td>Text Number Three</td><td>text</td><td><span class="value">3.5</span></td><td><span class="value">2</span></td><td><span class="value">3.5</span></td><td> </td><td> </td><td> </td></tr>
As you can see 3rd-8th cell can contain number (integer/double),   or number surrounded by span.
<tr class="abcData"><td>([\s\w]+)</td><td>([\s\w.-]+)</td><td>([\d.\s\w&;]+)</td><td>(\3)</td><td>(\3)</td><td>(\3)</td><td>(\3)</td><td>(\3)</td></tr>
My regex only works for first example (text number one) and I don't know how to write OR statement for this (I need result in the same 8 groups).
I'm testing my regex on http://derekslager.com/blog/posts/2007/09/a-better-dotnet-regular-expression-tester.ashx.
Upvotes: 0
Views: 82
Reputation: 34677
Do not use regex for HTML, use JSoup or a specialized parser instead. I'd use perl for this:
$tree->look_down('_tag', 'td', sub { push @text, $_->[0]->as_text; });
... or something like that.
Upvotes: 1