I want to search for a phrase that matches several words, following it, but stop early if I find another specific phrase.
For example, I want to combine up to three words after "going to", but stop the matching process if I encounter an "attempt". So, for example, "visiting the moon park" will lead to the "lunar park"; "going to the capital of Peru" will lead to a "capital" and "go to the moon to try cheesecake" will lead to a "moon".
Can this be done with a simple simple regular expression (preferably in Python)? I tried all the combinations that I could think of, but failed :).
source
share