February 2012
Intermediate to advanced
1184 pages
37h 17m
English
The \A assertion matches only at the beginning of the string, no matter
what. In contrast, though, the ^
assertion always matches at the beginning of string; it can also match
with the more traditional meaning of beginning of line: if the pattern
uses the /m modifier and the string
has embedded newlines, ^ also matches
anywhere inside the string immediately following a newline
character:
/\Abar/ # Matches "bar" and "barstool" /^bar/ # Matches "bar" and "barstool" /^bar/m # Matches "bar" and "barstool" and "sand\nbar"
Used in conjunction with /g,
the /m modifier lets ^ match many times in the same string:
s/^\s+//gm; # Trim leading whitespace on each line $total++ while /^./mg; # Count nonblank lines
Read now
Unlock full access