Starting with the following string:
and worda1 worda2 ... wordan and wordb1 wordb2 ... wordbn
The ... is not literal, but means that other words could also be there. And the words could be anything but 'and'.
I'd like to capture
wordb1 wordb2 wordbn
The problem is with the regex's I've written so far is that I've used \w, which then matches the 'and' and results in a greedy capture. Lookahead and lookbehind don't work either because of the arbitrary number of words that need to be captured.
Edit: here's an example:
and everyone went to the park and nobody was left at home
should capture:
nobody was left at home
The regex cannot hardcode the phrase "nobody was left at home", because it needs to capture any arbitrary sequence of words other than "and".
Even better:
and it was morning and everyone went to the park and nobody was left at home
should capture:
nobody was left at home
The big picture is that I'd like to only capture only up to the first "and", starting from the right.
I could write some code to do this, but wondering if there is a regex way to do this.
I'm using Python re, but open to other flavors of regex.
Thanks for any help.