text = Kes local: 6,072 (5,452WN, 620BWN) Kes import:3 (1WN, 2BWN) J kematian:46(45WN)
I want to get the substring after the word 'import' occur, before either 'WN' or 'BWN', whichever occur first, and match only 1 time.
I used
re.search(r"(import)(.*)(WN|BWN)", text, re.IGNORECASE).group(0)
re.search(r"(import)(.*)(WN|BWN){0,1}", text, re.IGNORECASE).group(0)
re.search(r"(import)(.*)(?!WN|BWN)", text, re.IGNORECASE).group(0)
# does not work # output
# 'import:3 (1WN, 2BWN) J kematian:46(45WN'
# 'import:3 (1WN, 2BWN) J kematian:46(45WN) J kumulatif: 2,040(0.42%) J kes di ICU:559 Pesakit Intubated:303'
# output that I want
# 'import:3 (1WN'
Can anyone explain why my approach doesn't work? and also appreciate your solution.