Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: Regexpby elusion (Curate) |
on Jul 25, 2002 at 20:42 UTC ( [id://185334]=note: print w/replies, xml ) | Need Help?? |
This code should work:
@colors = $new =~ m/(\[color=.*?\])/gi; First off, @colors will receive values that are kept by parentheses, and you don't have any in your regex. And second, the .* in your regex will make it match "[color=blue] blue [/color] word. And a [color=red] red [/color]" all at once because regexes are greedy -- they match as much as possible. By adding the ? behind .* it matches as little as possible. elusion : http://matt.diephouse.com
In Section
Seekers of Perl Wisdom
|
|