Regex Line and Word Boundaries
You can use boundary matching constructs to specify where in a string to apply a
matching pattern. For example, you can search for a particular pattern within a word boundary,
or search for a pattern at the beginning or end of a line.
Construct | Description | Example |
|---|---|---|
^
| Matches from the beginning of a line (multi-line matches are currently not
supported) | ^172 matches the "172" in IP address "172.18.1.11" but not in
"192.172.2.33" |
$
| Matches from the end of a line (multi-line matches are currently not
supported) | d$ matches the "d" in "maid" but not in "made" |
\b
| Matches within a word boundary | \bis\b matches the word "is" in "this is my island", but not
the "is" part of "this" or "island". \bis matches both "is" and
the "is" in "island", but not in "this". |
\B
| Matches within a non-word boundary | \Bb matches "b" in "sbin" but not in "bash" |