0

I have one sentence.

en ko
Neonatal(disseminated) listeriosis(P37.2) 신생아(파종성) 리스테리아증(P37.2)

i want this result

en ko
Neonatal listeriosis 신생아 리스테리아증

or

en ko
Neonatal(disseminated) listeriosis 신생아(파종성) 리스테리아증

I used the following regex

regex = "\(.*\)|\s-\s.*"
df['en'] = re.sub[regex,'',df['en')
df['ko'] = re.sub[regex,'',df['ko')

but result

en ko
Neonatal 신생아

My guess is that it recognizes the words before (and at the very end) the words disseminated and deletes them all. I want to delete only the code(P37.2) at the end. Help

이승우
  • 5
  • 2
  • It would be helpful to see the actual code you are running, given that regex usage and details can vary a LOT across different implementations. Especially given that this is likely to be related to the escaping of the parentheses – Jazz Weisman Nov 23 '22 at 02:34
  • Use `*?` instead of `*` to make it _non-greedy_. [Here an example](https://regex101.com/r/Ub6Nr3/1). – Ignatius Reilly Nov 23 '22 at 02:36
  • I've add the code I actually used. – 이승우 Nov 23 '22 at 02:37
  • Does this answer your question? [Regular expression to stop at first match](https://stackoverflow.com/questions/2503413/regular-expression-to-stop-at-first-match) – Ignatius Reilly Nov 23 '22 at 02:42

0 Answers0