1

I got strings like these:

Test 120,00 Euro yaddayadda
200 € with 18 months of blablabla
3.000,65 € something . And here s something more with 0815. And more.
1 Euro
Last item for 5.234.789,00 Euro.

and I want to get rid of everything except the price. So with these examples it should be

120,00
200
3.000,65
1
5.234.789,00

I already got

preg_replace("/[^0-9,.]/", "", $string);

but that ain't enough. It turns

3.000,65 € something . And here s something more with 0815. And more.

into

3.000,65.0815..

Close...but still not enough.

Thx!

TZP
  • 53
  • 5

1 Answers1

2

You can use:

$result = preg_replace('/^\D*(\b\d+([,.]\d+)*\b).*$/m', '$1', $str);

RegEx Demo

This regex:

\D*           # matches all non-digits from start
\b            # word boundary
\d+([,.]\d+)* # matches your floating point number in each line
(...)         # groups these numbers
.*$           # match rest of the line

And replacement is $1 which is captured number.

anubhava
  • 761,203
  • 64
  • 569
  • 643