|
Posted by gosha bine on 06/04/07 12:46
On 04.06.2007 13:58 GoL wrote:
> Hi all,
>
> I have a problem that I *think* is simple, but since I'm completely
> ignorant about regex expression I don't have a clue how to do it...
>
> What I need to do is to find all instances in a string where there are
> exactly 10 digits in a row, and replace the 4th, 5th and 6th digit
> with a # sign.
> 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"
>
>
>
> How do I do this?
> Greatful for any help.
>
> Thanks,
> /G
maybe
$regexp = '~
(
(?: ^ | \D)
\d{3}
)
\d{3}
(?=
\d{4}
(\D | $)
)
~x';
echo preg_replace($regexp, '$1###', $your_example));
--
gosha bine
extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
[Back to original message]
|