Bug #11461 Updated: \. after \- does not work
| From: | postings dot php dot net at hans-spath dot de | Date: | Tue, 14 May 2002 20:05:56 +0000 |
| Subject: | Bug #11461 Updated: \. after \- does not work | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-7665@lists.php.net to get a copy of this message | ||
ID: 11461
Updated by: postings.php.net@hans-spath.de
Reported By: aweber@multamedio.de
Status: Bogus
Bug Type: Regexps related
Operating System: Linux 2.2.16-SMP
PHP Version: 4.0.6RC3
New Comment:
@rasmus:
It sounds like you've mistaken "^" for "[^" ...
http://sunsite.utk.edu/gnu/regex/regex_17.html#SEC17
http://sunsite.utk.edu/gnu/regex/regex_23.html#SEC23
Previous Comments:
------------------------------------------------------------------------
[2002-05-14 12:31:25] rasmus@php.net
A bracket expression is a list of characters enclosed in
`[]'. It normally matches any single character from the
list (but see below). If the list begins with `^', it
matches any single character (but see below) not from the
rest of the list. If two characters in the list are sepa
rated by `-', this is shorthand for the full range of
characters between those two (inclusive) in the collating
sequence, e.g. `[0-9]' in ASCII matches any decimal digit.
It is illegal- for two ranges to share an endpoint, e.g.
`a-c-e'. Ranges are very collating-sequence-dependent,
and portable programs should avoid relying on them.
To include a literal `]' in the list, make it the first
character (following a possible `^'). To include a lit
eral `-', make it the first or last character, or the sec
ond endpoint of a range. To use a literal `-' as the
first endpoint of a range, enclose it in
[.' and .]' to
make it a collating element (see below). With the excep
tion of these and some combinations using `[' (see next
paragraphs), all other special characters, including `\',
lose their special significance within a bracket expres
sion.
------------------------------------------------------------------------
[2001-06-13 05:25:01] aweber@multamedio.de
I tried to check email with
$check =
ereg('^[0-9A-Za-z_\-\.]+@[0-9A-Za-z_\-]+\.[0-9A-Za-z_\-\.]+[0-9A-Za-z_\-]+$',$email);
This does not work with 'xxx-yyy@zzz.com', for example, althoug the
regular expression is correct. It works this way in any other
programming language.
But if you write it in the following way it also works fine in PHP:
$check =
ereg('^[\.0-9A-Za-z_\-]+@[0-9A-Za-z_\-]+\.[\.0-9A-Za-z_\-]+[0-9A-Za-z_\-]+$',$email);
Maybe the parser thinks of "-" as the range separator, althoug it is
written as \- ?
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=11461&edit=1