In the following string there are some numbers followed by two letters “ST”. How can I extract all of those numbers?
$str = '104 ST Lorem 104 ipsum (dolor) sit ST, 2000 ST adipiscing 2 2 ST elit.'
In the above string there is 104 ST, 2000 ST and 2 ST.
Advertisement
Answer
We can use preg_match_all
here with the pattern (d+) STb
:
$str = "104 ST Lorem 104 ipsum (dolor) sit ST, 2000 ST adipiscing 2 2 ST elit."; preg_match_all("/(d+) STb/", $str, $matches); print_r($matches[1]);
This prints:
Array ( [0] => 104 [1] => 2000 [2] => 2 )