|
Posted by Jim Michaels on 02/15/06 22:56
"Jim Michaels" <jmichae3@nospam.yahoo.com> wrote in message
news:lvGdnbfW8r7CLXbeRVn-pA@comcast.com...
>
> "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)){
>>
<?php if(ereg("[|]","|")) echo 1; else echo 0; ?>
1
<?php echo "\,"; ?>
\,
<?php if(ereg("[\,]","\\")) echo 1; else echo 0; ?>
1
so a | in an ereg class will be recognized as a |. And a \, will probably
be recognized as a \ and a comma.
>> '-' 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 or a whitespace \s?
> 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.
As I found out by another post session with Jason, ereg uses a different
regex type (POSIX extended) than that of preg_match (Perl-compatible).
so as he said, \ probably loses its significance in character classes in a
POSIX setting... (ereg), of which the PHP manual says pretty much nothing
but referring to regex(7) manual, the exception being preg_match and its
like functions (see PHP manual), which BTW also happen to be faster than
ereg (see PHP manual).
a faster equivelant to this above would probably be
if (preg_match("/^[\w\d,.+-]+$/",$string)){
I tested it to make sure I don't need to escape the . I guess I wouldn't
make sense anyway inside a character class matching any character, but I had
to make sure.
>
>> so you acually have 4 maching backslashes in the expression
>
>
Navigation:
[Reply to this message]
|