0

Say, I want to split a string on either "。」" or " 。" , but not twice on "。」"

So for example:

s = "Something something。」 something something。 something。」that's great!"

I want to return

s = "Something something。」\n something something。\n something。」\nthat's great!"

I have trouble figuring how to split 。」 and not get 。\n」 or 。\n」\n

echan00
  • 2,788
  • 2
  • 18
  • 35

1 Answers1

1

In python you can implement the suggestions in the comments like this:

import re

s = "Something something。」 something something。 something。」that's great!"
pattern = re.compile(r'(。」|。)')
pattern.sub(lambda match: match.groups()[0] + '\n', s)

"Something something。」\n something something。\n something。」\nthat's great!"

Matches are greedy by default so that the longer pattern is used if possible (no split in the leading if followed by ).