Reputation: 1966
I have some strings, each has one dollar amount in it (without the $) I would like to fish these amounts out via RegEx and add the $ to them.
Example strings:
UPS GND (Ground) 5.88
UPS 2DY (2 Day) 8.35
UPS 1DY (Next Day) 15.65
LTL COD 6.54
As you can see there are also some numbers in the service codes (sometimes) so I cant just look for numbers. I am horrible with RegEx!
Upvotes: 0
Views: 652
Reputation:
The following searchs for for one or more numbers, followed by a decimal, followed by two numbers:
preg_replace('/\d+\.\d{2}/', '$$0', $str)
Upvotes: 1