Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Regexp

by elusion (Curate)
on Jul 25, 2002 at 20:42 UTC ( [id://185334]=note: print w/replies, xml ) Need Help??


in reply to regexp problem using custom markup

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://185334]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-03-28 22:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found