【发布时间】:2015-09-01 05:51:22
【问题描述】:
有人知道在使用正则表达式从文本中提取单词时处理撇号的方法吗?
>>> import re
>>> s = re.compile(r"\b[A-Za-z0-9_\-]+\b")
>>> s.findall("I don't know Sally's 'special' friend.")
['I', 'don', 't', 'know', 'Sally', 's', 'special', 'friend']
想要的结果:
['I', "don't", 'know', 'Sally', 'special', 'friend']
This discussion 涵盖了如何查找整个单词,但不处理撇号。
【问题讨论】:
标签: python regex text-parsing