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  and asserts true wherever  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 MULTILINE mode, A matches only at the very beginning, while ^ is matched at every line start position
z Permanent end of input; in a multiline input using MULTILINE mode, z matches only at the very end while $ is matched at every line end position
Z Similar to z with the only difference being that it matches just before the optional line break at the very end of the input.
G End of the previous match; we will discuss it in advanced sections of the book in the next chapters.
Let's recall from the first chapter that [a-zA-Z0-9_] are called word characters. All other characters are considered non-word characters.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.228.99