Find/Replace using Regex

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
Persican
Forum Newbie
Posts: 2
Joined: Tue Feb 24, 2009 4:21 pm

Find/Replace using Regex

Post 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
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Find/Replace using Regex

Post by VladSun »

http://bg.php.net/manual/en/function.preg-replace.php

Take a look at the examples section.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: Find/Replace using Regex

Post by prometheuzz »

Code: Select all

echo preg_replace('/(\d+\.\d)(\d\d\.)/','$1 $2','8.546.');
Persican
Forum Newbie
Posts: 2
Joined: Tue Feb 24, 2009 4:21 pm

Re: Find/Replace using Regex

Post by Persican »

Tx guys for your answers.
I'll try that.

Best regards,
Phil
Post Reply