A common trick is to use the capture technique inside an unexplored positive look. Use this regex with preg_match_all :
(?=(1....1))
Watch the regex demo
Values are in $matches[1] :
$re = "/(?=(1....1))/"; $str = "001110000100001100001"; preg_match_all($re, $str, $matches); print_r($matches[1]);
See the reference guide :
Lookaround actually matches the characters, but then discards the match, returning only the result: match or no match. That is why they are called "statements." They do not consume characters in a string, but only claim whether a match is possible.
If you want to keep the regex match inside the lookahead , you need to place the brackets around the regex inside the lookahead , for example: (?=(regex)) ,
source share