I'd like to extract one or more word from a string containing multiple words matching the same pattern (regex python). Here's the line:
new_appointment_requested; general; SAT-newlead
From that line, I need to extract "SAT-" and whatever comes after it within that word. In this case the output should be "SAT-newlead". It can also be SAT-oldlead or something completely different, and there can be more than one word containing this pattern at a time. To capture all possible scenarios:
- find the word starting with "SAT-" (\b)
- if it is the final or only word in the string, extract the rest of the word,
- if there is a ; after the word (it's not the final word in the string), grab the word without the ;
- if more than one word matches this pattern, extract all instances as separate words
For some reason I can't wrap my head around Regex, so any help on this would be appreciated.
CodePudding user response:
Match SAT
and everything not a space, semicolon or newline:
\bSAT[^ ;\n]*
See live demo.