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

Posted by Jim Michaels on 02/15/06 12:02

"Jasen Betts" <jasen@free.net.nz> wrote in message
news:9d1.43ecf3ca.f3424@clunker.homenet...
> On 2006-02-09, Jim Michaels <jmichae3@nospam.yahoo.com> wrote:
>
>> "Palle Hansen" <palle@na.invalid> wrote in message
>> news:43cf4b9b$0$84031$edfadb0f@dtext01.news.tele.dk...
>>> yawnmoth wrote:
>>>
>>>> if (eregi("^[a-z0-9| |\,\-\+\.]+$",$string))
>>>
>>>> Why does $string = 'te\st' yield a match? The ereg expression doesn't
>>>> have a \\ in it...
>>>
>>> To have this expression make sence to me, it should look like
>>>
>>> if (eregi("^[a-z0-9 ,+.-]+$",$string)){
>>>
>>> '-' should be the first og last character
>>>
>>> all the special characters looses their meaning in a character class.
>>
>> if that's true, how yould you match a tab character \t
>
> when you say "\t" in a doouble-quote string the the \t is transformed
> into a tab character, and there is no \ in the actual string.
>
>>or a whitespace \s?
>
> you say "[:space:]" inside the brackets - eg: "[a-z[:space:]]".

sure enough - it worked. I guess it should. the manual said it was Perl 5
compatible RegEx. actually \s works in PHP too, but I think it also matches
a tab besides a space. a PHP extra.

>
> If you have shell access to a unix(etc) system do "man 7 regex."
>
>> Somehow I don't think they would do that.
>> I tried <?php print preg_match('/[\s]/'," \t "); ?> and it returned
>> 1.
>> it works. \t and \s works in a character class. you can escape things.
>> I
>> don't know who told you this.
>
> Only in perl perl regular expressions, not in POSIX extended regular
> expressions.
>
> The ereg... functions use POSIX extended regular expressions.

<?php if (ereg("/[\s]/"," ")) echo 1; else echo 0; ?>
0
ahhh. good to know. there must be a reason why they did that.

>
> Bye.
> Jasen

 

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

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