Is there a way in the PHP regex functions to get all possible matches of a regex even if those matches overlap?
e.g. Get all the 3 digit substrings \'/[\\d
Look-ahead assertions to the rescue!
preg_match_all('/(?=(\d{3}))/', $str, $matches);
print_r($matches[1]);
It basically captures whatever the look-ahead assertion is matching. Since the assertion is zero width, $matches[0]
will only contain empty strings, but $matches[1]
will contain the expected captured patterns.