|
Posted by gosha bine on 06/04/07 13:00
On 04.06.2007 14:52 Pavel Lepin wrote:
> GoL <usenet@^^.wwwspace.net._nospam_^^> wrote in
> <j5v763posshgstkulnj9rbvgfoabmh14qf@4ax.com>:
>> So if I have the string:
>>
>> "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"
>
> pavel@debian:~/dev/php$ cat r.php
> #!/usr/bin/php
> <?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@debian:~/dev/php$
>
Pavel, [\W$] doesn't mean "non-word or end of line" as you seem to
think. Metachars don't work in character classes.
--
gosha bine
extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
Navigation:
[Reply to this message]
|