Re: Regular Expressions?

From: Date: Fri, 20 Apr 2001 07:13:24 +0000
Subject: Re: Regular Expressions?
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-49520@lists.php.net to get a copy of this message
Hi Jason, @ 3:08:06 AM on 4/20/2001, Jason Caldwell wrote: > Sorry if I seem dense. Your answer (although probably right on target) > leaves me still confused :-) No problem at all. > The example you gave me: > $string = 'aaaa.aaaa'; > print(eregi("^([[:alnum:]]+\.[[:alnum:]]+)", $string) ? 'matched' : > 'no > match'); > Now with your example (above) the following MATCHED (when, I think it > shouldn't have:) > (example 1) > aaaa.a! Matches because there is *at least* one alnum after the \. It doesn't care about the ! as long as it found the a. > aaaa.a#$% Ditto here. > aaaa.a23!% Ditto here. > The following did NOT match. > (example 2) > a!.aaaa This didnt' match because of ^[[:alnum:]]+\. There's a [:punct:] between the [:alnum:] and the \. > a%!.aaaa Ditto here. > aaaa.!a34 No [:alnum:] after the \. Your expression asks for *at least one* [:alnum:] Changing + to * would make that match. > Now when I took your example and added the $ at the end, like so: > print(eregi("^([[:alnum:]]+\.[[:alnum:]]+)$", $string) ? 'matched' : > 'no > match'); > Everything that MATCHED in example 1 no longer matched, Right, because it had a [:punct:] before the end of the string and you forced it to only pick up [:alnum:]'s -Brian -- PGP is spoken here: 0xE4D0C7C8 Please, DO NOT carbon copy me on list replies.

« previous php.general (#49520) next »