Zero-width assertions

Zero-width or zero-length assertion in regular expressions means that there is a zero-length match that does not change the current position of the pointer in the input string. These assertions do not consume characters in the string but only assert whether a match is possible or not, giving us a binary true or false match result. Although many zero-width assertions are denoted inside parentheses, like groups, we will soon see that they do not capture any text. Zero-width assertions have no real meaning in back-references or in replacements.

We have already discussed a few zero-width assertions in the previous chapters, such as anchors and boundary assertions.

The Java regular expression engine allows many predefined ...

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.