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>


Reply via email to