Whatever the pattern regular expression pattern to search for all intersecting matches, it is enough to put this pattern in the forward validation:
(?=pattern)
In this case, the regular expression will be sequentially checked for each position in the text, and therefore can find intersecting matches:
(?=(1|2|3) (?1) (?1))
https://regex101.com/r/kO1wD8/3 Such a regular expression already finds two desired entries. Such a match has zero length, because the position in the text is checked, not the text, which means that to extract the text of the match, you need to place the template in a saving group
I want to immediately warn ( https://regex101.com/r/kO1wD8/4 ) that if you apply a regular expression to the text:
1 1 2 3 4 21 2 1
then it is possible that the third match is undesirable; in order to rule out such matches, it is necessary to do a retrospective check for the absence of a digit in front of the pattern:
(?=(?<!\d)(1|2|3) (?1) (?1))
https://regex101.com/r/kO1wD8/5
preg_match_all: php.net/manual/en/function.preg-match-all.php - andy.37preg_match_all, but it finds only1 1 2,1 2 3it does not find. - yevgeniyche