DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Variable-length Negation

07.18.2007
| 1489 views |
  • submit to reddit
        Everybody known the
<div[^>]*>
construction to match a tag. But how to match inside a tag ? We want something like:
<div>[^div]*</div>
but it don't work since [^div] has not this meaning ;)

This regexp do that (but don't manage nested markups, however).

<div>
(?:
  (?!</div>) # If not followed by </div>
  . # Match any character
)* # Non-capturing grouping
</div>