Get price value from a string

Shirish picture Shirish · Jan 16, 2012 · Viewed 10.3k times · Source

I have a string, where price value($544.50) can be anywhere in the string. eg: HP G60-630US Notebook: Laptops | RadioShack.com --> $259.97 (radioshack.com)

I need to get the value: 259.97 out of the string

For this i tried using some random regex's. But no luck!

Can someone help me, giving a proper regex string for retrieving this price value from a string.

Thanks in advance.

Answer

SERPRO picture SERPRO · Jan 16, 2012

This regex will work with multiple currencies: $ £ €

[\$\£\€](\d+(?:\.\d{1,2})?)

Example