You might want to check out Japhy's modules YAPE::Regex and
YAPE::Regex::Explain. You can pass in regular expressions and have it spit out
an explanation of what the parser is doing.
An example of (non) greedy matching would be something like:
$string = "<a href='learn.perl.org'>here</a>"; #you want to pull out the tags
and the content separately
$string =~ /(<.*>)([^<>]*)(<.*>)/; #won't work, the .* matches any character
including the '>' so you get the whole string in $1;
$string =~ /(<.*?>)([^<>]*?)(<.*?>)/; #I think this would work.
#Matches only as
many characters as is necessary for the entire match pattern to succeed.
#tags are in $1 and $3, content is in $2
I might have made a mistake with the above as I don't have an interpreter to run
it through at the moment, but I think the underlying info is sound.
Good luck!
Peter C.
Josh wrote:
> Hi all,
> I'm reading Mastering Regular Expressions and it discusses a
> non-greedy version of star. can someone explain how to write this
> non-greedy version of star. (i.e. how does it differ than just *)