M
Matt Garrish
Would anynoe care to enlighten me as to why the (.*?) pattern matches
greedily in the following example:
my $text =<<TEXT;
I wouldn't expect the following text to match
xyz 12345 abc
but it does and I lose this text as well
xyz 12345 abc
xyz 12345 abc
xyz 12345 abc
TEXT
$text =~ s/(xyz(.*?)abc\s*)+$//s;
print $text;
But if I change the regex to:
$text =~ s/(xyz(.*?)abc\s*)\1+$//s;
It works as expected.
Matt
greedily in the following example:
my $text =<<TEXT;
I wouldn't expect the following text to match
xyz 12345 abc
but it does and I lose this text as well
xyz 12345 abc
xyz 12345 abc
xyz 12345 abc
TEXT
$text =~ s/(xyz(.*?)abc\s*)+$//s;
print $text;
But if I change the regex to:
$text =~ s/(xyz(.*?)abc\s*)\1+$//s;
It works as expected.
Matt