Reputation: 942
m/(?<=\n)(?=$pattern)/
vs
m/(?<=\n)(?=^$pattern)/
The semantic is I want to match the "empty string" between a new line character and a pattern.
However, in Perl, the top one does what I want while the 2nd one doesn't.
Could someone explain the intricacies at play here with the "^" meta character?
Thanks
Upvotes: 2
Views: 61
Reputation: 98388
^
defaults to matching the beginning of the string; if you want to match the beginning of a line, you need to use the /m
flag or (?m:^)
.
Upvotes: 7