Anchors don’t match any characters; they match places
within a string. The two most common anchors are ^
and $
, which match the beginning and end of a
line, respectively. The following table lists the anchoring patterns
used to match certain boundaries in regular expressions:
Assertion | Meaning |
---|---|
| Matches at the beginning of the string (or
line, if |
| Matches at the end of the string (or line, if
|
| Matches at word boundary (between |
| Matches except at word boundary |
| Matches at the beginning of the string |
| Matches at the end of the string or before a newline |
| Matches only at the end of the string |
| Matches where previous |
| Suppresses resetting of search position when used with g. Without c, search pattern is reset to the beginning of the string. |
The $
and assertions can match not only at the
end of the string, but also one character earlier than that, if the
last character of the string is a newline.
3.144.47.208