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.

6
  • so, don't! what is your question? Commented Jan 25, 2011 at 13:16
  • @SilentGhost what don't you understand? Commented Jan 25, 2011 at 13:17
  • what problem do you have not using lazy evaluation? Commented Jan 25, 2011 at 13:18
  • 1
    don't use regex for html stackoverflow.com/questions/1732348/… Commented Jan 25, 2011 at 13:18
  • @SilentGhost I just want to not use lazy evaluation. Commented Jan 25, 2011 at 13:19

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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: Thanks! I think regular-expression.info is the source to go to for all things regex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.