Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 5th, 2009, 05:12 PM
ryel01 ryel01 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 227 ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 15 h 4 m 42 sec
Reputation Power: 15
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

Reply With Quote
  #2  
Old February 5th, 2009, 06:00 PM
Viper_SB's Avatar
Viper_SB Viper_SB is offline
Psycho Canadian
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jan 2001
Location: Canada
Posts: 4,845 Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 20 h 16 m 27 sec
Reputation Power: 634
Try this
PHP Code:
 $string '15\\\\\\.50';
$string preg_replace("/([0-9]+)\\\+\.([0-9]+)/""$1.$2"$string); 

Reply With Quote
  #3  
Old February 5th, 2009, 06:56 PM
ryel01 ryel01 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 227 ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 15 h 4 m 42 sec
Reputation Power: 15
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.

Reply With Quote
  #4  
Old February 5th, 2009, 07:01 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,690 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 3 h 43 m 47 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Quote:
Originally Posted by ryel01
Nope, that deletes the digits on both sides. :|

I just tried it and it works fine.

Reply With Quote
  #5  
Old February 5th, 2009, 07:05 PM
ryel01 ryel01 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 227 ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 15 h 4 m 42 sec
Reputation Power: 15
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!

Reply With Quote
  #6  
Old February 5th, 2009, 07:27 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,690 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 3 h 43 m 47 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Quote:
Originally Posted by ryel01
Thanks requinix!

Me? Thank Viper, all I did was check that it worked.

Reply With Quote
  #7  
Old February 5th, 2009, 11:26 PM
ryel01 ryel01 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 227 ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level)ryel01 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 15 h 4 m 42 sec
Reputation Power: 15
Ah, it's been a long day and night.

Thanks Viper_SB!




Regan

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Preg_replace to turn $12\\\\\\.50 = $12.50

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap