Given an arbitrary string of words (for simplicity each letter represents a word):
a b c d e f c g e b c f d g
I am trying to find a regex that allows me to match an expression (word b followed by word f with a distance of max 3 words), but not when overlapping with another expression (word c followed by word e with a distance of max 3 words).
and given the pattern-A to match b\s+(?:\S+\s+){1,3}f
(would match b c d e fand b c f)
and the not to overlap pattern-B c\s+(?:\S+\s+){1,3}e and pattern-C d\s+(?:\S+\s+){1,3}g
is there a combined regex to match b c f but not b c d e f because the latter is overlapping with pattern-B (c d e)
or because there is a partial overlap with pattern-C (d e f c g)?
I have added the string and patterns in regex101 for convenience.
I am using the python regex module (PCRE). Any help is appreciated.