go ahead... be a heretic | |
PerlMonks |
Re: Pattern Match n00bby skirnir (Monk) |
on Mar 14, 2008 at 20:59 UTC ( [id://674293]=note: print w/replies, xml ) | Need Help?? |
No, to make the .+ part non-greedy you'd have to place the '?' directly after the "+":
@{$pets} = $1 if $pet_list =~ /$some_variable\:(.+?);?/; But as the ';' is optional, the non-greedy match would stop matching after the first non-newline character. In your example you would get "b" in $1. It's best not to use "." if you don't really mean "any non-newline character". In your case I think [^;] would be the right thing to use, given that I understood properly what you want to do.
In Section
Seekers of Perl Wisdom
|
|