How to extract numbers preserving their formatting of a string in PHP?

2

I'm having a question, how can I do to extract numbers from a String in PHP preserving the formatting of it?

I found a solution on the forum in English, but when extracting the numbers the default date, for example, is not preserved.

$str = 'Paga. ref. a nota fiscal número 8888, com o cheque número 9999 em 14/08/2015';
preg_match_all('!\d+!', $str, $matches);
print_r($matches);

Source: Extract numbers from a string

    
asked by anonymous 14.08.2015 / 14:32

1 answer

2
$re = "/([0-9\/])/"; 
$str = "Paga. ref. a nota fiscal número 8888, com o cheque número 9999 em 14/08/2015"; 

preg_match_all($re, $str, $matches);

See in Regex. link

Explaining

0-9 - Within the string I want only numbers.

\ - Exit bar, otherwise the command will give error when putting the date bar.

/ - In addition to the numbers, I also want the bar to be selected. But it could be:

% of% trace

- underscore

_ points

    
14.08.2015 / 14:35