473,487 Members | 2,711 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

help understanding an ereg expression

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...

Also, what does | | do? Normally, it'd mean 'or', but inside of []'s?
And two of them?

Jan 19 '06 #1
18 2003
On Wed, 18 Jan 2006 21:36:20 -0800, yawnmoth 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... the \ is escaping the s, so is invisible to the regular expression. To
have an \ in the string, you'd need to see \\

Also, what does | | do? Normally, it'd mean 'or', but inside of []'s?
And two of them?

Well, one | inside a class ( [...] ) matches |. Not too sure what 2 of
them mean, though. The space between them will also be matched. Using | as
an or would require the use of parentheses as well.

tbh, I'm not too sure the author really knew what they were doing, as
almost all those characters with special powers ( like \ ) lose them all
when between []'s (:

hth,

Steve
Jan 19 '06 #2
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.
so you acually have 4 maching backslashes in the expression
Jan 19 '06 #3

"Steve" <Th*****@Aint.Valid> wrote in message
news:pa****************************@Aint.Valid...
On Wed, 18 Jan 2006 21:36:20 -0800, yawnmoth 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... the \ is escaping the s, so is invisible to the regular expression. To
have an \ in the string, you'd need to see \\


That's not true. \s is whitespace. tabs or spaces.
\. means a "." as opposed to matching any character. don't know why they
escaped the comma.
\- was necessary so "-" is not interpreted as a range.
\+ may not have been necessary, but safe anyway.

Also, what does | | do? Normally, it'd mean 'or', but inside of []'s?
And two of them?

Well, one | inside a class ( [...] ) matches |. Not too sure what 2 of
them mean, though. The space between them will also be matched. Using | as
an or would require the use of parentheses as well.

tbh, I'm not too sure the author really knew what they were doing, as
almost all those characters with special powers ( like \ ) lose them all
when between []'s (:

hth,

Steve

Feb 9 '06 #4


"yawnmoth" <te*******@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Say I have the following script:

<?
$string = 'test';
if (eregi("^[a-z0-9| |\,\-\+\.]+$",$string))
^ means starting from the beginning of the line
[] means match one character in the set between the brackets.
+ after the [] means match 1 or more of those.
$ means must hit the end of the line.
{
echo 'matches!';
}
else
{
echo 'no match';
}
?>

Why does $string = 'te\st' yield a match? The ereg expression doesn't
have a \\ in it...

Also, what does | | do? Normally, it'd mean 'or', but inside of []'s?
And two of them?

Feb 9 '06 #5
"Jim Michaels" <jm******@nospam.yahoo.com> wrote:
[...]
Why does $string = 'te\st' yield a match? The
ereg expression doesn't have a \\ in it...

the \ is escaping the s, so is invisible to the regular
expression. To have an \ in the string, you'd need
to see \\


That's not true. \s is whitespace. tabs or spaces.


"\s" means whitespace in a regular expression, but not in the string
being matched against.

P.
Feb 9 '06 #6

"Palle Hansen" <pa***@na.invalid> wrote in message
news:43***********************@dtext01.news.tele.d k...
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 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.
so you acually have 4 maching backslashes in the expression

Feb 9 '06 #7

"Steve" <Th*****@Aint.Valid> wrote in message
news:pa****************************@Aint.Valid...
On Wed, 18 Jan 2006 21:36:20 -0800, yawnmoth 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... the \ is escaping the s, so is invisible to the regular expression. To
have an \ in the string, you'd need to see \\

Also, what does | | do? Normally, it'd mean 'or', but inside of []'s?
And two of them?

Well, one | inside a class ( [...] ) matches |. Not too sure what 2 of
them mean, though. The space between them will also be matched. Using | as
an or would require the use of parentheses as well.

tbh, I'm not too sure the author really knew what they were doing, as
almost all those characters with special powers ( like \ ) lose them all
when between []'s (:

<?php print preg_match('/[\s]/'," \t "); ?>
1

Where did you hear this? this has been a part of Perl RE's for a long time.
Perl's REs were pretty much ported to PHP. PERL RE was POSIX if I am not
mistaken.
I've been able to escape things in [] character classes in UNIX and
grep-like programs for as long as I can remember. I thought I remember
having to so I could avoid weird behavior.
it's probably not safe to avoid escaping "-" because of its interpretation
as a range. better to be safe than sorry.

hth,

Steve

Feb 9 '06 #8

"Palle Hansen" <pa***@na.invalid> wrote in message
news:43***********************@dtext01.news.tele.d k...
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.
so you acually have 4 maching backslashes in the expression


nope. I just tried it. I've been able to escape things in RE char classes
for a long time. otherwise, you couldn't include things like tabs \t,
whitespace \s, newline \n, return \r and other control characters, word
characters \w, decimal digits \d. We didn't get Perl's character classes
like ::alpha:: (I don't think).
Feb 9 '06 #9
On 2006-02-09, Jim Michaels <jm******@nospam.yahoo.com> wrote:

"Steve" <Th*****@Aint.Valid> wrote in message
news:pa****************************@Aint.Valid...
On Wed, 18 Jan 2006 21:36:20 -0800, yawnmoth 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... the \ is escaping the s, so is invisible to the regular expression. To
have an \ in the string, you'd need to see \\

Also, what does | | do? Normally, it'd mean 'or', but inside of []'s?
And two of them?

Well, one | inside a class ( [...] ) matches |. Not too sure what 2 of
them mean, though. The space between them will also be matched. Using | as
an or would require the use of parentheses as well.

tbh, I'm not too sure the author really knew what they were doing, as
almost all those characters with special powers ( like \ ) lose them all
when between []'s (:

<?php print preg_match('/[\s]/'," \t "); ?>
1

Where did you hear this? this has been a part of Perl RE's for a long time.
Perl's REs were pretty much ported to PHP. PERL RE was POSIX if I am not
mistaken.
Possibly they share a common ancestor. They are different now.
I've been able to escape things in [] character classes in UNIX and
grep-like programs for as long as I can remember. I thought I remember
having to so I could avoid weird behavior.
I suspect you're mistaken.

this from regex(7):
..
.. To include a literal ]' in the list, make it the first character (fol-
.. lowing 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 .]' to
.. make it a collating element (see below). With the exception of these
.. and some combinations using [' (see next paragraphs), all other spe-
.. cial characters, including \', lose their special significance within
.. a bracket expression.
it's probably not safe to avoid escaping "-" because of its interpretation
as a range. better to be safe than sorry.


depends on the definition of safe.
Bye.
Jasen
Feb 10 '06 #10
On 2006-02-09, Jim Michaels <jm******@nospam.yahoo.com> wrote:

"Palle Hansen" <pa***@na.invalid> wrote in message
news:43***********************@dtext01.news.tele.d k...
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.
so you acually have 4 maching backslashes in the expression


nope. I just tried it. I've been able to escape things in RE char classes
for a long time. otherwise, you couldn't include things like tabs \t,
newline \n, return \r and other control characters,


those aren't escaped in the regular expression, they are escaped in the
string. The resular expression parser doesn't see the slashes associated
with those symbols, rather it sees the actual character.
whitespace \s, word characters \w, decimal digits \d.
they don't work inside bracket expressions.
We didn't get Perl's character classes
like ::alpha:: (I don't think).


???

--

Bye.
Jasen
Feb 10 '06 #11
On 2006-02-09, Jim Michaels <jm******@nospam.yahoo.com> wrote:

"Steve" <Th*****@Aint.Valid> wrote in message
news:pa****************************@Aint.Valid...
On Wed, 18 Jan 2006 21:36:20 -0800, yawnmoth 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... the \ is escaping the s, so is invisible to the regular expression. To
have an \ in the string, you'd need to see \\


That's not true. \s is whitespace. tabs or spaces.


That's not true the "\s" is outside of the regualar expression.
"\s" is the same as '\s' and prints as \s.
\. means a "." as opposed to matching any character. don't know why they
escaped the comma.
\- was necessary so "-" is not interpreted as a range.
\+ may not have been necessary, but safe anyway.


There are four \ in the regex. one is sufficient to cause a match.
in extended regex \ loses its special meaning inside bracket expressions.
(except its normal string meanings \t etc... where the \ insn't
actually present in the string anyway)

To include a literal '-' in a bracket expression have it first or last.
Also, what does | | do? Normally, it'd mean 'or', but inside of []'s?
And two of them?

Well, one | inside a class ( [...] ) matches |. Not too sure what 2 of
them mean, though. The space between them will also be matched. Using | as
an or would require the use of parentheses as well.
two are the same as one.
tbh, I'm not too sure the author really knew what they were doing, as
almost all those characters with special powers ( like \ ) lose them all
when between []'s (:


gotta agree there. possibly he thought he was writing a perl regex, where
he should have used preg_match.

Bye.
Jasen
Feb 10 '06 #12
On 2006-02-09, Jim Michaels <jm******@nospam.yahoo.com> wrote:
"Palle Hansen" <pa***@na.invalid> wrote in message
news:43***********************@dtext01.news.tele.d k...
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:]]".

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.

Bye.
Jasen
Feb 10 '06 #13

"Jasen Betts" <ja***@free.net.nz> wrote in message
news:ad****************@clunker.homenet...
On 2006-02-09, Jim Michaels <jm******@nospam.yahoo.com> wrote:

"Steve" <Th*****@Aint.Valid> wrote in message
news:pa****************************@Aint.Valid...
On Wed, 18 Jan 2006 21:36:20 -0800, yawnmoth 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...
the \ is escaping the s, so is invisible to the regular expression. To
have an \ in the string, you'd need to see \\
Also, what does | | do? Normally, it'd mean 'or', but inside of []'s?
And two of them?
Well, one | inside a class ( [...] ) matches |. Not too sure what 2 of
them mean, though. The space between them will also be matched. Using |
as
an or would require the use of parentheses as well.

tbh, I'm not too sure the author really knew what they were doing, as
almost all those characters with special powers ( like \ ) lose them all
when between []'s (:

<?php print preg_match('/[\s]/'," \t "); ?>
1

Where did you hear this? this has been a part of Perl RE's for a long
time.
Perl's REs were pretty much ported to PHP. PERL RE was POSIX if I am not
mistaken.


Possibly they share a common ancestor. They are different now.
I've been able to escape things in [] character classes in UNIX and
grep-like programs for as long as I can remember. I thought I remember
having to so I could avoid weird behavior.


I suspect you're mistaken.

this from regex(7):
.
. To include a literal ]' in the list, make it the first character (fol-
. lowing 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 .]' to
. make it a collating element (see below). With the exception of these
. and some combinations using [' (see next paragraphs), all other spe-
. cial characters, including \', lose their special significance within
. a bracket expression.

OK, I may be mistaken there about UNIX RegEx. I thought for sure I've used
them in grep and sed.

This is from the PHP manual:
Ranges operate in ASCII collating sequence. They can also be used for
characters specified numerically, for example [\000-\037]. If a range that
includes letters is used when caseless matching is set, it matches the
letters in either case. For example, [W-c] is equivalent to [][\^_`wxyzabc],
matched caselessly, and if character tables for the "fr" locale are in use,
[\xc8-\xcb] matches accented E characters in both cases.

The character types \d, \D, \s, \S, \w, and \W may also appear in a
character class, and add the characters that they match to the class. For
example, [\dABCDEF] matches any hexadecimal digit. A circumflex can
conveniently be used with the upper case character types to specify a more
restricted set of characters than the matching lower case type. For example,
the class [^\W_] matches any letter or digit, but not underscore.
it's probably not safe to avoid escaping "-" because of its
interpretation
as a range. better to be safe than sorry.


depends on the definition of safe.
Bye.
Jasen

Feb 15 '06 #14

"Jasen Betts" <ja***@free.net.nz> wrote in message
news:9d****************@clunker.homenet...
On 2006-02-09, Jim Michaels <jm******@nospam.yahoo.com> wrote:
"Palle Hansen" <pa***@na.invalid> wrote in message
news:43***********************@dtext01.news.tele.d k...
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

Feb 15 '06 #15

"Jim Michaels" <jm******@nospam.yahoo.com> wrote in message
news:lv********************@comcast.com...

"Palle Hansen" <pa***@na.invalid> wrote in message
news:43***********************@dtext01.news.tele.d k...
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


Feb 15 '06 #16
On 18 Jan 2006 21:36:20 -0800, "yawnmoth" <te*******@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 :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Feb 15 '06 #17

"Jim Michaels" <jm******@nospam.yahoo.com> wrote in message
news:ab********************@comcast.com...


"yawnmoth" <te*******@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Say I have the following script:

<?
$string = 'test';
if (eregi("^[a-z0-9| |\,\-\+\.]+$",$string))


^ means starting from the beginning of the line
[] means match one character in the set between the brackets.
+ after the [] means match 1 or more of those.
$ means must hit the end of the line.
{
echo 'matches!';
}
else
{
echo 'no match';
}
?>

Why does $string = 'te\st' yield a match? The ereg expression doesn't
have a \\ in it...

Also, what does | | do? Normally, it'd mean 'or', but inside of []'s?
And two of them?



after my tests, this ereg is clearly wasn't written for any PHP function.
were it written for preg_match, it is missing // around the ends and the
case insensitivity using \w instead of a-z. it's not writen for ereg
because of the |'s and the \'s. Only 1 should be necessary, but clearly they
put two in because they thought it had some special meaning. I don't
remember what significance (if any) | had in a Perl RE (which preg_match
series of functions is compatible with). This could have maybe been a
bad(?) Perl RE port-attempt to PHP.
Feb 15 '06 #18
On 2006-02-15, Jim Michaels <jm******@nospam.yahoo.com> wrote:

"Jasen Betts" <ja***@free.net.nz> wrote in message
news:ad****************@clunker.homenet...
On 2006-02-09, Jim Michaels <jm******@nospam.yahoo.com> wrote:

"Steve" <Th*****@Aint.Valid> wrote in message
news:pa****************************@Aint.Valid...
On Wed, 18 Jan 2006 21:36:20 -0800, yawnmoth 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...
the \ is escaping the s, so is invisible to the regular expression. To
have an \ in the string, you'd need to see \\

>
> Also, what does | | do? Normally, it'd mean 'or', but inside of []'s?
> And two of them?
Well, one | inside a class ( [...] ) matches |. Not too sure what 2 of
them mean, though. The space between them will also be matched. Using |
as
an or would require the use of parentheses as well.

tbh, I'm not too sure the author really knew what they were doing, as
almost all those characters with special powers ( like \ ) lose them all
when between []'s (:
<?php print preg_match('/[\s]/'," \t "); ?>
1
Where did you hear this? this has been a part of Perl RE's for a long
time.
Perl's REs were pretty much ported to PHP. PERL RE was POSIX if I am not
mistaken.


Possibly they share a common ancestor. They are different now.
I've been able to escape things in [] character classes in UNIX and
grep-like programs for as long as I can remember. I thought I remember
having to so I could avoid weird behavior.


I suspect you're mistaken.

this from regex(7):
.
. To include a literal ]' in the list, make it the first character (fol-
. lowing 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 .]' to
. make it a collating element (see below). With the exception of these
. and some combinations using [' (see next paragraphs), all other spe-
. cial characters, including \', lose their special significance within
. a bracket expression.

OK, I may be mistaken there about UNIX RegEx. I thought for sure I've used
them in grep and sed.

This is from the PHP manual:


a URL would have been nice, anyway, I used grep and found it.
Ranges operate in ASCII collating sequence. They can also be used for
characters specified numerically, for example [\000-\037]. If a range that
includes letters is used when caseless matching is set, it matches the
letters in either case. For example, [W-c] is equivalent to [][\^_`wxyzabc],
matched caselessly, and if character tables for the "fr" locale are in use,
[\xc8-\xcb] matches accented E characters in both cases.

The character types \d, \D, \s, \S, \w, and \W may also appear in a
character class, and add the characters that they match to the class. For
example, [\dABCDEF] matches any hexadecimal digit. A circumflex can
conveniently be used with the upper case character types to specify a more
restricted set of characters than the matching lower case type. For example,
the class [^\W_] matches any letter or digit, but not underscore.


reference.pcre.pattern.syntax.html
----
but that's on a page describing Perl Compatible Regular Expressions,

The preg_.+ functions do that, the posix ones do not

Bye.
Jasen
Feb 16 '06 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2333
by: Stefan Gangefors | last post by:
I'm trying to figure out what I'm doing wrong when using ereg(). This is my regexp: ereg("^]$", "]"); and that does'n work, but this does: ereg("^$", "[");
3
20966
by: Martin Lucas-Smith | last post by:
Is there some way of using ereg to detect when certain filename extensions are supplied and to return false if so, WITHOUT using the ! operator before ereg () ? I have an API that allows as an...
0
2784
by: mcp6453 | last post by:
I am trying to use Jack's FormMail script (http://www.dtheatre.com/scripts/formmail). Since I'm brand new at PHP and not very good at HTML, I have an easy question, which I will narrow down. When...
12
1892
by: hq4ever (at) 012 (dot) net (dot) il | last post by:
function testemail($email) { $validEmailExpr = "^(?)*@(?)*$"; return eregi($validEmailExpr, $email); } $email = "foo@bar.gov.mil"; testmail($email); //return TRUE
2
1206
by: Yannick Benoit | last post by:
Hi! I use this to find all links in a page : *(href)*=*(+) but recently i found out that it only works if links are setup this way: <a href = "... I would like to know if someone can help...
8
5448
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
6
1625
by: Cerebral Believer | last post by:
Is this a good ereg statement? if (!ereg("^+(\.+)*@+(\.{1,})*\.({2,}){1}$",$email_1 or $email_2)) { unset($_GET); $message_new = "<font color='#cc0000'>$email_1 or $email_2 is not a valid...
4
1848
by: ollie.mitch | last post by:
Hi, I need two ereg expressions in my PHP code. One of them needs to check that a string only contains letters, and the other needs to check that the string only contains letters and commas...
3
283
by: William Gill | last post by:
I am not to sharp on my regular expressions because I haven't used them in quite a while. So I am relearning regex and the PHP regex functions at the same time. Which means when I screw up, I'm...
0
7137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7349
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5442
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4874
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
267
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.