|  | Posted by Alan Little on 05/23/06 03:52 
Carved in mystic runes upon the very living rock, the last words of AndyJeffries of comp.lang.php make plain:
 
 > On Mon, 22 May 2006 13:47:39 -0500, Alan Little wrote:
 >>> 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.
 >>
 >> OK. I don't believe it's standard, however.
 >
 > 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.
 
 --
 Alan Little
 Phorm PHP Form Processor
 http://www.phorm.com/
  Navigation: [Reply to this message] |