Next: The Match-end-of-line Operator ($
), Up: Anchoring Operators [Contents][Index]
^
)This operator can match the empty string either at the beginning of the string or after a newline character. Thus, it is said to anchor the pattern to the beginning of a line.
In the cases following, ‘^’ represents this operator. (Otherwise, ‘^’ is ordinary.)
RE_CONTEXT_INDEP_ANCHORS
is set, and it is outside
a bracket expression.
(
… )
or \(
… \)
), and The Alternation Operator (|
or \|
).
These rules imply that some valid patterns containing ‘^’ cannot be
matched; for example, ‘foo^bar’ if RE_CONTEXT_INDEP_ANCHORS
is set.
If the not_bol
field is set in the pattern buffer (see GNU Pattern Buffers), then ‘^’ fails to match at the beginning of the
string. This lets you match against pieces of a line, as you would need to if,
say, searching for repeated instances of a given pattern in a line; it
would work correctly for patterns both with and without
match-beginning-of-line operators.