Let me start by saying I've googled extensively for quite a few hours before asking this here, and I'm quite desperate if I've chosen to post here.
I have a few strings with the following format (approximated):
"firstword text ONE lastword"
"firstword text TWO lastword"
I need to extract the text
after the 'firstword'
and before 'ONE'
or 'TWO'
.
So my output for the aforementioned strings would have to be:
"text"
How do I split or partition the string so I can:
- remove the first word (I already know how to do this with str.split(' '))
- retain the text which comes before any of the 'ONE' or 'TWO'. (I thought it was supposed to look something like str.split('ONE' | 'TWO'), but that obviously doesn't work and I haven't managed to find a solution right now.
If possible, I would like to solve it with split()
or partition()
, but regex would be fine as well.
Thank you for your help and sorry if this is a dumb question.