/^((http|ftp):\/\/)?.+$/
In my opinion the problem is that ' .+' means 'anything',
and ''" is matched by this part of the regex
("" is anything too).
regards
Pedro
----- Original Message -----
From: "Roberto Ruiz" <[EMAIL PROTECTED]>
To: <beginners@perl.org>
Sent: Friday, July 29, 2005 6:52 AM
Subject: Re: regex puzzle
On Fri, Jul 29, 2005 at 01:48:15PM +0800, bingfeng zhao wrote:
See following sample code:
my @address = ("http://test", "http://", "www", "", "ftp:/foo" );
for (@address)
{
print "\"$_\" passed! \n" if /^((http|ftp):\/\/)?.+$/;
# ^ ^
# these parentesis are making an atom of the
# enclosed part of the regex
}
why "http://" and "ftp:/foo" can pass the check?
Because the () atomize the first part of your regex and then the ? is
asking for 0 or 1 of that atom.
Droping the ()?: /^(http|ftp):\/\/.+$/
Or, more redable: m!^(http|ftp)://.+$!
And a little shorter: m!^(ht|f)tp://.+$!
HTH,
Roberto Ruiz
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>