>>> line = 'asdf fjdk; afed, fjek,asdf, foo'
如何快速把里面的单词提取出来:
导入正则表达式模块
>>> import re
>>> re.split(r'[;,s]s*', line) ['asdf', 'fjdk', 'afed', 'fjek', 'asdf', 'foo']
当你使用 re.split() 函数时候,需要特别注意的是正则表达式中是否包含一个括号捕获分组
re.split()
如果使用了捕获分组,那么被匹配的文本也将出现在结果列表中