Re: Regular Expressions?

From: Date: Fri, 20 Apr 2001 07:08:06 +0000
Subject: Re: Regular Expressions?
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-49517@lists.php.net to get a copy of this message
Brian -- Sorry if I seem dense. Your answer (although probably right on target) leaves me still confused :-) 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! aaaa.a#$% aaaa.a23!% The following did NOT match. (example 2) a!.aaaa a%!.aaaa aaaa.!a34 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, and in-fact, just everything I wanted to match -- matched -- ie. just letters and numbers. So... even though I had the [:alnum:] tag in the end -- without the $ at the end it seems pointless? So, I guess my (dense) question is -- why? Why doesn't it just work with the [:alnum:] tag? I'm assuming ALNUM stands for Alpha-Numeric *only*? "Brian Clark" <brianj@fusionwerks.com> wrote in message news:53206844944.20010420024926@fusionwerks.com... > Hi Jason, > > @ 2:40:34 AM on 4/20/2001, Jason Caldwell wrote: > > > I'm a little lost as to the exact function of the following: > > > ^ and $ > > ^ beginning of a string. > $ end of a string. > > > I noticed in the example below... that when I added the $ to the end of the > > expression, I wasn't able anymore to put a non-alphanumeric character in the > > end, for example (without the $) > > > I was able to enter the following and get a 'match' > > > aaa.a! <-- matched > > Matches the expression with one or more alnum's before the \. and one > or more after the \. > > ! is [:punct:] > > > aaa.! <-- no match > > No alnum after the \. If you want to match that, replace the + with a > * > > > after I put the $ on the end > > > aaa.a! <-- no match > > Doesn't match the expression \.[[:alnum:]]+$ > > > aaa.aa32 <-- match... > > > So, am I to understand that the ^ and $ are used to tell the expression that > > it *must* match what the expression expects? > > Yep; more precisely, ^[something]$ matches the whole string. > > > -Brian > -- > PGP is spoken here: 0xE4D0C7C8 > Please, DO NOT carbon copy me on list replies. > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#49517) next »