string replace multiple items

Do a str.replace('; ', ', ') and then a str.split(', ')

or

import re
re.split('; |, ', string_to_split)

>>> a='Beautiful, is; better*than\nugly'
>>> import re
>>> re.split('; |, |\*|\n',a)
['Beautiful', 'is', 'better', 'than', 'ugly']

参考:
[1] https://stackoverflow.com/questions/4998629/split-string-with-multiple-delimiters-in-python

posted @ 2023-05-09 11:11  xiaoxuxli  阅读(10)  评论(0编辑  收藏  举报