开发者

matching this html element in regex? (without lazy matching!)

开发者 https://www.devze.com 2023-02-06 10:02 出处:网络
I\'d like to match everything betweentags. what\'s the regex to do that? A bit like <tr[^>]*>开发者_如何学C.*?</tr>

I'd like to match everything between tags.

what's the regex to do that?

A bit like

  <tr[^>]*>开发者_如何学C.*?</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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消