I was tasked with extracting an advertiser name from a string. I came across this solution which seems to work very well using regex.
Using regular expressions - documentation for further reference
import re
some_string = "2022_PULSEPOI_COH_PHRM_DAILY_REPORT"
def get_advertiser_name(string):
if advertiser := re.search(
"2022_PULSEPOI_(.+?)_PHRM_DAILY_REPORT", string
):
return advertiser[1]
# returns COH