This question sounds interesting. I don't know php , but I decided to challenge myself to resolve it with python , which I'm more used to.
import regex s = r"This is an example text to explain the problem I am having with the regular expression" [elem for t in regex.findall(r'\m(?|(((\w{4,})\W+\w{3,})\W+\w{3,})|((\w{4,})\W+\w{3,})|(\w{4,}))', s, overlapped=True) for elem in t if elem != '']
I used the regex module and its overlapped option, which starts the next match with the character following the current one. A regular expression returns tuples of the type:
[('This', '', ''), ('example text', 'example', ''), ('text', '', ''), ('explain the problem', 'explain the', 'explain'), ('problem', '', ''), ('having with the', 'having with', 'having'), ('with the regular', 'with the', 'with'), ('regular expression', 'regular', ''), ('expression', '', '')]
So, from there I do another loop to extract those fields that are not empty, which gives:
['This', 'example text', 'example', 'text', 'explain the problem', 'explain the', 'explain', 'problem', 'having with the', 'having with', 'having', 'with the regular', 'with the', 'with', 'regular expression', 'regular', 'expression']