A good article on Regular Expression in Perl

I found a good one here: http://www.anaesthetist.com/mnm/perl/Findex.htm#regex.htm.
The author pointed out some very useful features of regex in Perl, especially on the "greedy" manner of Perl. He said, Perl will match as much the portion of text to the pattern as possible.
E.g :
regex=/a(.+)b/ and the string $s="axxbyyb"
What stored in $1 is "xxbyy" not "xx" cause it was matched greedily.
To obtain the minimum matched, which makes $1 to be "xx", we need to turn off the greedy behavior by /a(.+?)b/, i.e putting a ? afterward.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: