Search code examples
phpregexpreg-match

PHP regular expression get float value between brackets


I have a little problem with getting some numbers from a string.

For example I have this kind of str:

qweqeqe (qweqwe) AASD 213,21 ( -1201,77 EUR )

I need the numbers with comma that are between brackets Result: -1201,77 The value also can be positive. I have already managed to get float value, but from all string. I have this: !\d+(?:\,\d+)?! but it gets all numbers in a str.


Solution

  • try this pattern :

    $pattern = "#\([\s]*(-{0,1}[0-9]+,[0-9]+)[\s]*[A-Za-z]*[\s]*\)#";