i am currently trying to match specific sentences based on the words they contain and their order. I am doing this mostly with the lookahead assertion based on this structure:
[^>.\]]*(?="The desired Words)[^<.\]]*
So i am for example looking for sentences that talk about Vacation in the Maledives. To match the sentence: i´ll book a vacation to the Maledives. I could look for sentences that contain the word vacation and afterwards maledives.
The expression [^>.\]]*(?=([Vv]cation.*[Mm]aledives))[^<.\]]* using .* causes problems because the word "Maledives" can also appear in later sentences (Example Wrong)
My solutionw as to use the expression ([,'`´() \\]*\w+){0,X}\s* instead of .*, to indicate that "Maledives" has to follow "vacation" within the same sentences and with a maximum of X words between them, changing to this structure:
[^>.\]]*(?=([Vv]cation([,'`´() \\]*\w+){0,X}\s*[Mm]aledives))[^<.\]]* (Example Correct)
Unfortunately this expression is quite computationally intensive and leads to catastrophic backtracking if the range {0,X} is set to high.
Do you have any other suggestions how to look for sentences containing specific words in order?