|
Posted by Steve on 01/19/06 09:57
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
Navigation:
[Reply to this message]
|