I need a JS regex to match a string based only on a known first and last sub-string and number of spaces - and I don't care about the length or the nature of what is between the first and last sub-strings (other than the exact number of spaces).
The following is a possible start string (from which I get the first and last sub-strings and the number of spaces):
cat apple dog mouse
From this, I now know the string starts with cat, ends with mouse and contains exactly 3 spaces (they could be be anywhere between the ends, but they will not be consecutive).
The string I need to match against might be:
catfish mouse mouse dormouse mouse mouse
or cat mouse mouse mouse mouse mouse
So, what I need to match would be, in the first case catfish mouse mouse dormouse, and in the second case cat mouse mouse mouse - in both cases a string starting with cat, ending with mouse and containing exactly 3 spaces. At the moment, all my attempts match the entire sample string above, not just from cat to the third mouse. Here is my latest failure:
cat(?:(?![\s]{4,}).*)mouse
I have a strong suspicion I'm overthinking this - but thanks for any suggestions.