|
Posted by M. Sokolewicz on 04/04/05 17:00
Kim Madsen wrote:
>>-----Original Message-----
>>From: M. Sokolewicz [mailto:tularis@php.net]
>>Sent: Monday, April 04, 2005 3:08 PM
>
>
>
>>>Putting the ^ _inside_ [] means NOT, so if any of the chars a-z0-9 is in
>>
>>the string it´s NOT matched.
>
>
>>actually, that's not entirely correct. The regexp basically means that
>>if there is any character in the string which is NOT alphanumeric, then
>>it is matched. So basically it returns true if there is a
>>non-alphanumeric char, and false otherwise. However, AFAIK the regexp
>>should be delimited, since if it isn't it behaves "differently"... I
>>just can't remember how differently it is exactly =/
>
>
> It _is_ correct. [^] means that whatever is in the [] must not be in the checked var to be true! Look in "mastering regular expressions" if You´re in doubt. There´s an example [^1-6] meaning if a digit between 1 and 6 is not in the value checked, it´s true:
which is exactly what I said...
>
> $var1 = "123";
> $var2 = "789";
>
> if(ereg("[^1-6]", $var1))
> print "$var1 is true";
> else
> print "$var1 is false";
>
> returns false
>
> if(ereg("[^1-6]", $var2))
> print "$var2 is true";
> else
> print "$var2 is false";
>
> returns true
>
> It´s untested though :-)
I just wasn't too sure about absence of the regexp-delimiter...
>
> --
> Med venlig hilsen / best regards
> ComX Networks A/S
> Kim Madsen
> Systemudvikler/systemdeveloper
Navigation:
[Reply to this message]
|