|
Posted by Alan Little on 11/09/62 11:48
Carved in mystic runes upon the very living rock, the last words of Andy
Jeffries of comp.lang.php make plain:
> On Mon, 22 May 2006 19:52:24 -0500, Alan Little wrote:
>>> On p79 of Mastering Regular Expressions by Jeffrey E F Friedl (ISBN
>>> 1-56592-257-3) it says:
>>>
>>> "In limited-metacharacter-class implementations, other metacharacter
>>> (including in most tools, even backslashes) are not recognized. So,
>>> for example, you can't use \- or \] to insert a hyphen or a closing
>>> bracket in to the class." This precedes a list of characters that
>>> are available in these limited implementations which are
>>> specifically: a leading caret, the closing bracket and a dash as a
>>> range operator.
>>>
>>> I'm sure that book details the "standard" for regular expressions in
>>> most people's eyes and that book (as quoted above) uses \- as the
>>> syntax to insert a literal hyphen with a metacharacter class
>>> ([...]).
>>>
>>> So it would seem that while [^0-9-] works in PHP/Perl, it's actually
>>> not standard and I am correct to use [^0-9\-] in order to ensure
>>> maximum compatibility with future version which may implement the
>>> standard more strictly.
>>
>> That's a good reference, but I don't follow you. The part you quoted
>> from the book says you *can't* use \- to insert a hyphen in the
>> class.
>
> In case it's not clear, that's a book on Regular Expressions and not
> specifically about PHP regexes.
I understand.
> In a *limited-metacharacter-class implementation*. Those
> implementations can only accept leading caret, closing bracket and a
> hyphen as a range character (i.e. there's no way to find a hyphen, a
> slash or any other non-alphanumeric character). PHP is not a
> limited-metacharacter-class implementation.
Pardon my density, but I still don't follow you. The book says:
>>> "So, for example, you can't use \- or \] to insert a hyphen or a
>>> closing bracket in to the class."
You say:
>>> I am correct to use [^0-9\-] in order to ensure
The book says it's incorrect, but you're saying it's correct? Am I
missing something?
--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Navigation:
[Reply to this message]
|