You are here: Re: help understanding an ereg expression « PHP Programming Language « IT news, forums, messages
Re: help understanding an ereg expression

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация