You are here: Re: ereg_replace question « PHP Programming Language « IT news, forums, messages
Re: ereg_replace question

Posted by Andy Jeffries on 05/22/06 22:13

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.

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация