Search code examples
phppreg-match

Skip white space with preg_match


So I am parsing a google spreadsheet and stuck at this problem:

$str = '‎20.00 €';
preg_match("/\d*.\d*/", $str, $output);
var_dump($output);

working example: http://www.phpliveregex.com/p/ggg

This is how it looks like: http://sandbox.onlinephpfunctions.com/code/14f9f8aa635f329f5b150b626d84da46746f064c

There is some white space which won't allow preg_match to find 20.00. Don't know how to deal with it. I have tried trim but it won't work..


Solution

  • Simply escape that .

    DEMO

    preg_match("/\d*\.\d*/", $str, $output);
    

    . Matches any character except line break in REGEX