如何在Python中使用多个分隔符拆分字符串?
我们可以使用re.split(delimiter, str)方法使用多个分隔符拆分字符串。它需要一个分隔符的正则表达式和需要拆分的字符串。例如:
a='Beautiful, is; better*than\nugly'
import re
print(re.split('; |, |\*|\n',a))
我们得到输出:
['Beautiful', 'is', 'better', 'than', 'ugly']
更多Python相关文章,请阅读:Python 教程
极客教程