#!/usr/bin/perl use strict; use warnings; use v5.20; my $s = <<'ENDSTR'; aaa : AAA bbb : BBB ccc : CCC ENDSTR my $m = 'bbb'; my $a = $1 if $s =~ s/^$m *: (.*?)$/$1/rsm; my $b = $1 if $s =~ s/^$m *: (.*)$/$1/rm; print "a: $a\n"; print "b: $b\n";
You see, $ only works at the end or just before a | all the m modifier does is match at the beginning/end of every line instead of the absolute beginning and absolute end. else $ gets confused with a variable, imagine: ~/(.)$./ ~/(.)\$./
In reply to Re: Why multiline regex doesn't work?
by FreeBeerReekingMonk
in thread Why multiline regex doesn't work?
by nbd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |