O'Reilly logo

Java 9 Regular Expressions by Anubhava Srivastava

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Be careful with capturing groups inside a lookahead or lookbehind atomic group

You learned to use capturing groups inside lookahead or lookbehind patterns in the preceding examples. However, you must remember that lookaround expressions are zero-width atomic groups. The regex engine exits from these groups as soon as an assertion is evaluated to true or false. Due to this fact, there is no backtracking inside these groups.

Consider the following three regular expressions. The first one is without any lookahead or atomic group, the second regex uses a lookahead expression, and the third regex uses an atomic group. Note that in each of the regex patterns, we use a capturing group to match and capture zero or more word characters inside the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required