match at the beginning of any line, including the first

Posted by JoelFan on Stack Overflow See other posts from Stack Overflow or by JoelFan
Published on 2010-03-12T19:42:11Z Indexed on 2010/03/12 19:47 UTC
Read the original article Hit count: 315

Filed under:
|

According the the Perl documentation on regexes:

By default, the "^" character is guaranteed to match only the beginning of the string ... Embedded newlines will not be matched by "^" ... You may, however, wish to treat a string as a multi-line buffer, such that the "^" will match after any newline within the string ... you can do this by using the /m modifier on the pattern match operator.

The "after any newline" part means that it will only match at the beginning of the 2nd and subsequent lines. What if I want to match at the beginning of any line (1st, 2nd, etc.)?

© Stack Overflow or respective owner

Related posts about perl

Related posts about regex