Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regex Query Failure 1

Status
Not open for further replies.

MadJock

Programmer
May 25, 2001
318
GB
Hi,

I am trying to find write a Reqex query to return all characters between
Code:
<td class="CelluleClairBleuCenter" align="center">

and

Code:
</tr>

I've written the following line, which gives a runtime exception:
Code:
Regex regex = new Regex("<td class=\"CelluleClairBleuCenter\" align=\"center\">(?<data>*)</tr>");

The intent is "take everything between these two bits of HTML and store it in a group called 'data'". However, I get the following exception:

Argument Exception: parsing "<td class="CelluleClairBleuCenter" align="center">(?<data>*)</tr>" - Quantifier {x,y} following nothing.

I have tried excaping the * which stops the error but does not find any matches.

Would be very grateful for any help.

Thanks,

Graeme

"Just beacuse you're paranoid, don't mean they're not after you
 
>Argument Exception: parsing "<td class="CelluleClairBleuCenter" align="center">(?<data>*)</tr>" - Quantifier {x,y} following nothing.
It means the quantifier * (meaning {0,} corresponding to {x,y} in the message) is not following no pattern to match.

This is one non-greedy alternative match to end with </tr> on the same row. (Greedy verson seems very unreasonable. Besides, non-greedy until </td> seems make better sense.)
[tt]
Regex regex = new Regex("<td class=\"CelluleClairBleuCenter\" align=\"center\">(?<data>[highlight].[/highlight]*[red]?[/red])</tr>");
[/tt]
 
Thanks tsuji for code and explanation. Only issue is that the </tr> is not on the same row - any suggestions?

Graeme

"Just beacuse you're paranoid, don't mean they're not after you
 
Replace the . by [\s\S] for instance.
[tt] Regex regex = new Regex([red]@[/red]"<td class=[red]"[/red]"CelluleClairBleuCenter[red]"[/red]" align=[red]"[/red]"center[red]"[/red]">(?<data>[red][\s\S][/red]*?)</tr>");
[/tt]
 
Tsuji,

Works a treat! Thanks for your help.

Graeme


"Just beacuse you're paranoid, don't mean they're not after you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top