Re: regex puzzle
- From: dsl58893@xxxxxxxxxxxxxxxx (Flemming Greve Skovengaard)
- Date: Fri, 29 Jul 2005 11:33:50 +0200
bingfeng zhao wrote:
See following sample code:
<CODE>
use warnings;
use strict;
my @address = ("http://test", "http://", "www", "", "ftp:/foo" );
for (@address)
{
print "\"$_\" passed! \n" if /^((http|ftp):\/\/)?.+$/;
}
</CODE>
the running result is: "http://test" is valid. "http://" is valid. "www" is valid. "ftp:/foo" is valid.
why "http://" and "ftp:/foo" can pass the check?
Because ((http|ftp):\/\/) is optional ( the ? following it does that ), so any line with anything between the start and end of the line will pass.
-- Flemming Greve Skovengaard FAITH, n. a.k.a Greven, TuxPower Belief without evidence in what is told <dsl58893@xxxxxxxxxxxxxxxx> by one who speaks without knowledge, 4112.38 BogoMIPS of things without parallel.
.
- Prev by Date: Podsaferadio
- Next by Date: Want code to display date in different timezone
- Previous by thread: RE: regex puzzle
- Next by thread: Re: regex puzzle
- Index(es):