代码如下:
text = "Sir John Doe, married to Mrs Jane Doe, Sir Jack Doe, Mrs Mary Doe"
splitter = re.split('Sir|Mrs', text)
我希望文本被单词"Sir"或"Mrs"分割,除非前面有字符串"married to".
Current output:
''
'John Doe, married to'
'Jane Doe,'
'Jack Doe,'
'Mary Doe'
Desired output:
''
'John Doe, married to Mrs Jane Doe,'
'Jack Doe,'
'Mary Doe'