The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Regex Programming
|
Preg_replace to turn $12\\\\\\.50 = $12.50
Discuss Preg_replace to turn $12\\\\\\.50 = $12.50 in the Regex Programming forum on Dev Shed. Preg_replace to turn $12\\\\\\.50 = $12.50 Regular expressions forum covering PCRE and POSIX techniques, practices, and standards. Regular expressions help shorten coding time by providing the ability to compact many lines of code into one string.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 5th, 2009, 05:12 PM
|
|
|
|
Preg_replace to turn $12\\\\\\.50 = $12.50
Hi
Can anyone show me the correct preg_replace regular expression to match "\\\\\\." with 1 or more digits on either side?
my current version below cuts off whatever digit is directly to the left of the "." for some reason - ie. it turns 15\\\\\\.50 into 1.50
Code:
$string = preg_replace("/[0-9](\\\{6}\.)[0-9]/",".",$string);
Regan
|

February 5th, 2009, 06:00 PM
|
 |
Psycho Canadian
|
|
Join Date: Jan 2001
Location: Canada
|
|
Try this
PHP Code:
$string = '15\\\\\\.50';
$string = preg_replace("/([0-9]+)\\\+\.([0-9]+)/", "$1.$2", $string);
|

February 5th, 2009, 06:56 PM
|
|
|
Quote: | Originally Posted by Viper_SB
PHP Code:
$string = '15\\\\\\.50';
$string = preg_replace("/([0-9]+)\\\+\.([0-9]+)/", "$1.$2", $string);
|
Nope, that deletes the digits on both sides. :|
I just want to "replace" the "\\\\\\." with "." if it has a digit on both sides of it.
|

February 5th, 2009, 07:01 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
Quote: | Originally Posted by ryel01 Nope, that deletes the digits on both sides. :| |
I just tried it and it works fine.
|

February 5th, 2009, 07:05 PM
|
|
|
Quote: | Originally Posted by requinix I just tried it and it works fine. |
Ahh you're right, sorry I missed the "$1.$2" when pasting it into my page.
WORKS PERFECTLY!!!
Thanks requinix! 
|

February 5th, 2009, 07:27 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
Quote: | Originally Posted by ryel01 Thanks requinix!  |
Me? Thank Viper, all I did was check that it worked.
|

February 5th, 2009, 11:26 PM
|
|
|
Ah, it's been a long day and night.
Thanks Viper_SB!
Regan
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|