|
Posted by Andy Jeffries on 05/22/06 16:57
On Thu, 18 May 2006 20:56:59 -0500, Alan Little wrote:
> Carved in mystic runes upon the very living rock, the last words of Andy
> Jeffries of comp.lang.php make plain:
>
>> Yes. The - sign isn't listed in the range (i.e. it would be [^0-9.\-])
>> so it will remove it from the output
>
> In brackets, you only escape the [] characters themselves. Your expression
> will allow the \ character in the string.
I appreciate your enthusiasm but did you actually test this before trying
to correct me ;-)
$ cat test.php
<?php print preg_match("/[\-]/", '\\')."\n"; ?>
$ php test.php
0
According to your login, the \ in the string should have matched against
either "\ or -", but unsurprisingly it didn't.
However, you do make the good point that you don't *need* to escape the -,
I just do it for readability so there's no mistaking that I meant a
literal dash and not part of a range that I forgot to complete.
Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos
[Back to original message]
|