I've been on this one for a while and can't seem to work it out. Here's what I am trying to do. Given three words word1, word2 and word3, I would like to construct a regex which will match them in that order, but with a set of potential words between them (except a new line).
For example, if I had the following:
word1 = what
word2 = the
word3 = hell
I would like to match the following strings, with a single match:
"what the hell"
"what in the hell"
"what the effing hell"
"what in the 9 doors of hell"
I thought I could do the following (allowing for 0 to 5 words to exist between each word variable):
regex = "\bword1(\b\w+\b){0,5}word2(\b\w+\b){0,5}word3\b"
Alas, no, it doesn't work. It's important that I have a way to specify a m to n word distance between words (where m always < n).