I'm trying to extract a string in the middle of a line with or without a particular word on the end. For example, this line:
START - some words and not THIS
should return "some words and not" and likewise, the line:
START - some words and not
should also return the same string. I've tried using lookahead from examples I've found with alternation for EOL, but adding the alternation returns a string ending with THIS. Here is the python regex:
[^-]*- (.+(?= THIS|$))
Removing |$ works, except when the line ends without THIS. The data I'm parsing has a small number of entries missing "THIS", so I need to account for both. What's the correct pattern for this?