I have a line with text, numbers and symbols. I am trying to extract numbers and characters from a string with limited success. Instead of getting all the numbers and characters, I get only part of it. Below I will explain my regular expression in order to make it more understandable and understandable.
\d : any number
[+,-,*,/,0-9]+ : 1 or more of any +,-,*,/, or number
\d : any number
Code:
$string = "text 1+1-1*1/1= text";
$regex = "~\d[+,-,*,/,0-9]+\d~siU";
preg_match_all($regex, $string, $matches);
echo $matches[0][0];
Expected results
1+1-1*1/1
Actual Results
1+1
source
share