Page 1 of 1

Find/Replace using Regex

Posted: Tue Feb 24, 2009 4:25 pm
by Persican
Hi all.

I'm trying to find a way to insert a white space in the middle of the returned expression.

For example :

8.546.

becomes

8.5 46.

I'm using (\d+\.\d\d\d\.) to match the pattern (it works fine).

My question is how can I insert a white space after the 5 (in that case).l

Tx in advance,
Phil

Re: Find/Replace using Regex

Posted: Tue Feb 24, 2009 4:54 pm
by VladSun
http://bg.php.net/manual/en/function.preg-replace.php

Take a look at the examples section.

Re: Find/Replace using Regex

Posted: Wed Feb 25, 2009 2:05 am
by prometheuzz

Code: Select all

echo preg_replace('/(\d+\.\d)(\d\d\.)/','$1 $2','8.546.');

Re: Find/Replace using Regex

Posted: Wed Feb 25, 2009 10:27 am
by Persican
Tx guys for your answers.
I'll try that.

Best regards,
Phil