php - preg_match expression including white space -


so i'm trying parse sequence of numbers extracted external web page.

preg_match('#([0-9]{3}\s[0-9]{3}\s[0-9]{3}){1}#', $element, $match); 

won't return result although echoing $element shows correct expression:

341 102 408 aaa bccc 

of course when try above regexp above string on online regexp testers got expected result... i'm thinking there may invisible caracter in place of white space can't find it. i'm getting crazy...

edit:

strangely remove every whitespace of input string except expression i'm trying extract:

$element = preg_replace("/\s/", "", $element); 

try

preg_match('#([0-9]{3}\s+[0-9]{3}\s+[0-9]{3}){1}#u', $element, $match); 

to make regex engine unicode-aware, , allow more 1 whitespace character between digits; perhaps have non-ascii whitespace in there.

that said, can reduce to

preg_match('#(?:[0-9]{3}\s+){2}[0-9]{3}#u', $element, $match); 

and find match result in $match[0] if succeeded.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -