I have been on this for a while and seem to be unable to handle this. Here is what I am trying to do. Given the three words word1, word2 and word3, I would like to build a regular expression that will match them in that order, but with a set of potential words between them (except for a new line).
For example, if I had the following:
word1 = what
word2 = the
word3 = hell
I would like to match the following lines with one 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 (let's say that between each word variable there were from 0 to 5 words):
regex = "\bword1(\b\w+\b){0,5}word2(\b\w+\b){0,5}word3\b"
Alas, no, this will not work. The important thing is that I have a way to specify the distance between words between words (where m is always <n).
source
share