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:06

On Mon, 22 May 2006 13:47:39 -0500, Alan Little wrote:
>>> 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 ;-)
>
> Yes, I did. However, I checked with ereg(), which does allow the \
> character, given the expression you posted earlier.

Ah, ereg isn't standard, it's PHP dodgy partial regular expression engine.

>> 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.

AFAIK Perl is the standard for regular expression implementation and:

$ cat test.pl
#!/usr/bin/perl
$string = "\\";
if ($string =~ /[\-]/) {
print "matches\n";
}
else {
print "doesn't match\n";
}
$ ./test.pl
doesn't match

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

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