1

i have the text:

  <a href="blahblahblah-dynamic" class="blahblahblah-dynamic" 
  title="blahblahblah-dynamic">2.550,00 €</a>1000 € 900 € 5000 € ......

and the expression:

#(\d+[\.\,]\d*?)\s?[€]#su

that matches:

550,00

example in: regexr

How can I match the whole: 2.550,00 ?

p.s I dont want to match the others 1000, 900 and numbers without , and/or . In other words, I want to match d,d or d.d,d so the question possible duplicate, does not cover my case.

Can someone help me on this?

qwertyg
  • 127
  • 10
  • You could try `#([\d.,]*?)\s?[€]#su`, but this also allows things like `1.00,0 €` – Nigel Ren Jul 05 '18 at 06:26
  • 1
    Possible duplicate of [Regular expression to match numbers with or without commas and decimals in text](https://stackoverflow.com/questions/5917082/regular-expression-to-match-numbers-with-or-without-commas-and-decimals-in-text) – Nigel Ren Jul 05 '18 at 06:27
  • You will need adjust the regex in the duplicate to reverse the commas and dots as it's assuming 1,200.02 (for example) – Nigel Ren Jul 05 '18 at 06:28

2 Answers2

1

You might use:

([0-9]{1,3}(?:.[0-9]{3})*\,[0-9]+)\s?€

This will match in a capturing group 1-3 digits. Then repeats in a group a dot and 3 digits and at the end will match a comma followed by one or more digits.

After the capturing group \s?[€] is matches but is not part of the group.

If you want to match exactly 2 digits after the comma you could update ,[0-9]+ to ,[0-9]{2}

As an alternative you could match your value without a capturing group and use a positive lookahead (?=\s?[€]) to assert that what is on the right side is an optional whitespace character followed by

[0-9]{1,3}(?:.[0-9]{3})*\,[0-9]+(?=\s?€)

The fourth bird
  • 154,723
  • 16
  • 55
  • 70
0

i'm guessing you got that value in a variable or something , why not try get it with

$value = substr($dataReceivedFromA, 0, -1);  // returns "2.550,00 "

i really think there is no point in using regex here if you only wanna get rid of the sign