You are here: Re: regex/preg_replace? How do I do this? « PHP Programming Language « IT news, forums, messages
Re: regex/preg_replace? How do I do this?

Posted by Pavel Lepin on 06/04/07 14:20

gosha bine <stereofrog@gmail.com> wrote in
<46640ea3$0$2892$6e1ede2f@read.cnntp.org>:
> On 04.06.2007 14:52 Pavel Lepin wrote:
>> GoL <usenet@^^.wwwspace.net._nospam_^^> wrote in
>> <j5v763posshgstkulnj9rbvgfoabmh14qf@4ax.com>:
>>> "some text here 1234567890 more text 0987654321 and more
>>> text"
>>>
>>> I want it replaced with:
>>>
>>> "some text here 123###7890 more text 098###4321 and more
>>> text"
>>
>> <?php
>> $str =
>> '"1111111111 some text here 1234567890, more text ' .
>> '0987654321 and more text 2222222222"' ;
>> echo (
>> preg_replace (
>> '/([\W^]\d{3})\d{3}(\d{4}[\W$])/' ,
>> '\\1###\\2' ,
>> $str ) .
>> "\n" ) ;
>> ?>
>> pavel@debian:~/dev/php$ ./r.php
>> "111###1111 some text here 123###7890, more text
>> 098###4321 and more text 222###2222"
>
> Pavel, [\W$] doesn't mean "non-word or end of line" as you
> seem to think. Metachars don't work in character classes.

That seems to be the case, indeed. I was baffled as to why
it still seemed to work even despite that, and then
suddenly realized the string I used started and ended with
double-quotes.

--
Pavel Lepin

 

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

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