breq
breq

Reputation: 25516

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..

Upvotes: 1

Views: 365

Answers (3)

Ramdas Gaikar
Ramdas Gaikar

Reputation: 76

Just need to escape the dot character.

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

Upvotes: 2

Jayesh Chitroda
Jayesh Chitroda

Reputation: 5039

You can remove spaces in between the string using:

$string = preg_replace('/\s+/', '', $string);

Upvotes: 2

Thamilhan
Thamilhan

Reputation: 13313

Simply escape that .

DEMO

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

. Matches any character except line break in REGEX

Upvotes: 2

Related Questions