regular Expression problem
| From: | Hubert dot Ried at publica dot de | Date: | Tue, 31 Oct 2000 17:13:58 +0000 |
| Subject: | regular Expression problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-22964@lists.php.net to get a copy of this message | ||
Hi everybody !
I do have a problem using reg. expression in php(3 and 4).
As fas as I understood, I can escape *every* special character but here is the
point.
Well, it seems, that I cant escape the hyphen.
Have a look at that little code snippet:
<?
$name = "a-.b";
$ret = ereg("^[a-z\.\-]*$",$name); // This returns true (1) ....
echo "Ret1 :".$ret."<br>";
$ret = ereg("^[a-z\-\.]*$",$name); // ... whereas this returns *FALSE* !!
echo "Ret2 :".$ret."<br>";
$ret = ereg("^[a-z\.-]*$",$name); // This returns true (1) ....
echo "Ret1 :".$ret."<br>";
$ret = ereg("^[a-z-\.]*$",$name); // ... whereas this returns a Warning:
REG_ERANGE in /export/home/ried/weltbild/info.php on line blabla ...
echo "Ret2 :".$ret."<br>";
?>
The problem is the hyphen. It is only recognized(?), when I put it at the end of
the pattern.
So I can't escape the hyphen?
And I do have to put the hyphen at the end of the pattern to make it recognized?
Is that correct ???
Thanks anyway
Hubert
________________________________
Publica Data-Service GmbH
Steinerne Furt 72
86167 Augsburg
mailto:Hubert.Ried@publica.de