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

Posted by Andy Jeffries on 12/18/64 11:48

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.

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.

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

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