Re: regular Expression problem
| From: | Monte Ohrt | Date: | Tue, 31 Oct 2000 21:08:59 +0000 |
| Subject: | Re: regular Expression problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-23007@lists.php.net to get a copy of this message | ||
As a rule of thumb: always put the hyphen at the end of the pattern when
you want the literal meaning. The reason for this is because the hyphen
may have an ambiguous meaning elsewhere in the pattern. You may want the
literal "-", or maybe you want a range, such as "a-z"
Hubert.Ried@publica.de wrote:
>
> 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
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
Monte Ohrt <monte@ispi.net>
http://www.ispi.net/