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

Boundary constructs

Boundary constructs allow us to specify where our matches should start or stop by restricting our matches to certain boundaries. We avoid matching unwanted text by adding restrictions to the start and stop positions of the matching text using boundary matchers. Here are all the boundary constructs available in Java regular expressions:

Boundary Matcher Name Meaning
\b Word boundary; position between a word and a non-word character
\B Non-word boundary; it compliments \b and asserts true wherever \b asserts false
^ Line-start anchor, which matches the start of a line
$ Line-end anchor, which matches just before the optional line break at the end of a line
\A Permanent start of input; in a multiline input using ...

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