note 57385 added to function.ereg
| From: | Jasonknarlin at yahoo dot com dot au | Date: | Sun, 02 Oct 2005 16:48:22 +0000 |
| Subject: | note 57385 added to function.ereg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-96189@lists.php.net to get a copy of this message | ||
A previous post stated "Beware that eregs in PHP4 are broken, for instance if you want to match
"a to z, 0,9 and -" you might want to use [a-z0\\-9] but it will silently fail due to a
bug"
This is incorrect, this is not a bug, nor is ereg broken on this count!
In my testing of ereg, matching
-' [' or `]' within a bracketed
expression ereg works exactly according to the regex man page http://www.tin.org/bin/man.cgi?section=7&topic=regex
referred from the php manual page at http://au3.php.net/manual/en/ref.regex.php
From the regex man page you will find that within a bracketed expression to match a literal
]' make it the first character (following a possible ^'). To include a
literal -' make it the first or last character, or the second endpoint of a range. To
use a literal -' as the first endpoint of a range, enclose it in [.' and
.]'
spook says
if you want a string to work that matches "a to z", "A to Z", "0 to
9", "-", "[", "]" and "_" you will have to use this
expression:
([0-9a-zA-Z_]|\\-|\\[|\\])
end spook says
A neater solution is
[]0-9a-zA-Z_[-]
I hope this settles that ereg is not buggy or broken in this way
----
Manual Page -- http://www.php.net/manual/en/function.ereg.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57385
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57385&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57385&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57385&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57385&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57385&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57385&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57385&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57385&report=yes
Search -- http://master.php.net/manage/user-notes.php