|
Posted by Andy Hassall on 02/15/06 23:27
On 18 Jan 2006 21:36:20 -0800, "yawnmoth" <terra1024@yahoo.com> wrote:
>Say I have the following script:
>
><?
>$string = 'test';
>if (eregi("^[a-z0-9| |\,\-\+\.]+$",$string))
>{
> echo 'matches!';
>}
>else
>{
> echo 'no match';
>}
>?>
>
>Why does $string = 'te\st' yield a match? The ereg expression doesn't
>have a \\ in it...
You've got the slashes in front of the punctuation near the end. One or more
are being picked up as a literal slash in the character class.
Once you remove them, then watch out for the sequence ",-+" inside the
character class, as that ends up as a character range comma to plus - although
that doesn't make much sense since comma is after plus in ASCII.
If you want - in a character class it should be the final character.
>Also, what does | | do? Normally, it'd mean 'or', but inside of []'s?
>And two of them?
The second | is redundant. "| |" in a character class matches | and a space.
--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
[Back to original message]
|