> -----Original Message-----
> From: Joe Sprankle [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, July 31, 2002 1:44 PM
> To: [EMAIL PROTECTED]
> Subject: more regex woes...
> 
> 
> Hi all,
> I am brand new to perl, and programming at that. I'm learning 
> alot from
> Robert's Perl Tutorial and I was hoping someone culd possibly 
> clear up the
> following from the tutorial:

What is "Robert's Perl Tutorial"?

> 
> $_='My email address is <[EMAIL PROTECTED]>.';
> print "Match 1 worked :$1:" if /(<*)/i;
> 
> $_='<My email address is <[EMAIL PROTECTED]>.';
> print "Match 2 worked :$1:" if /(<*)/i;
> 
> $_='My email address is <[EMAIL PROTECTED]<<<<>.';
> print "Match 3 worked :$1:" if /(<*>)/i;
> 
> Match 1 is true. It doesn't return anything, but it is true
> because there are 0 < at the very
> start of the string.
> Match 2 works. After the 0 < at the start of the string, 
> there is 1 < so the
> regex can match that too.
> Match 3 works. After the failing on the first < , it jumps to 
> the second.
> After that, there are plenty more to match right up until the required
> ending.
> I've been doing fine so far but I just can't seem to 
> completly grasp this
> part.

What don't you understand? Why they capture what they do?
They all capture the leftmost, longest substring matching the
pattern.

An regex like /<*/ will *always* match at the beginning of the
string, since '*' means "zero or more of the preceding item".
So this regex will only capture <'s if they appear at the beginning
of the string. Perhaps that's what "Robert" is trying to illustrate.

The regex /<*>/ won't necessarily match at the beginning, because
the zero or more <'s must be followed by one > char.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to