Negative lookbehind

A negative lookbehind assertion asserts true if the pattern inside the lookbehind is not matched.

Here is its syntax:

(?<!...) 

For example, (?<!xyz)abc asserts that there cannot be the string, xyz, just before matching the string, abc.

Here are a few important points about lookaround regex patterns:

  • Lookaround patterns are atomic. Like atomic groups, once a lookaround pattern is matched, the regex engine exits immediately from that lookaround, returning just a true or false assertion.
  • Lookaround patterns don't move from the current position. All patterns are evaluated from the current position. The position remains the same after the lookaround assertions are completed.
  • If a regular expression uses multiple lookaround ...

Get Java 9 Regular Expressions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.