Re: regex puzzle
- From: pcalais@xxxxxxxxxxxx (Pedro Henrique Calais)
- Date: Fri, 29 Jul 2005 12:50:09 -0300
/^((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" <rruiz@xxxxxxxxxxxxxxxx>
To: <beginners@xxxxxxxx>
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: beginners-unsubscribe@xxxxxxxx For additional commands, e-mail: beginners-help@xxxxxxxx <http://learn.perl.org/> <http://learn.perl.org/first-response>
.
- References:
- Re: regex puzzle
- From: Roberto Ruiz
- Re: regex puzzle
- Prev by Date: RE: Grep uniqueness issue
- Next by Date: Re: Getting Date Stamp of a file on a Win32 System
- Previous by thread: Re: regex puzzle
- Next by thread: Podsaferadio
- Index(es):
Relevant Pages
|
|