For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > July 2005 > Re: regex puzzle









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: regex puzzle
Flemming Greve Skovengaard

2005-07-29, 5:01 pm

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@vip.cybercity.dk> by one who speaks without knowledge,
4112.38 BogoMIPS of things without parallel.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com