0

I'd like to match everything between tags.

what's the regex to do that?

A bit like

  <tr[^>]*>.*?</tr> 

But I'd like to not use lazy evaluation.

I want to match each pair like the regex above, but not using lazy evaluation.

barlop
  • 11,553
  • 7
  • 74
  • 103

1 Answers1

2

Instead of matching lazily, you could use a negative lookahead (if your flavour supports that). Your example would translate to

 <tr[^>]*>((?!</tr>).)*</tr>  

Of course, you should actually not use regex to parse HTML, as you might have guessed from the comments to your question. =) These expressions may fail horribly on nested tags, comments, and javascript.

Jens
  • 24,655
  • 6
  • 74
  • 116
  • that is really an excellent use of negative lookahead - quite inspiring!.. is there any particular article or part of a book that inspired "((?!abc).)*?" and good closing paragraph too. – barlop Jan 26 '11 at 08:01
  • @barlop: Thanks! I think regular-expression.info is the source to go to for all things regex. – Jens Jan 26 '11 at 08:22