|
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
[Back to original message]
|