【发布时间】:2018-04-17 14:37:32
【问题描述】:
我有这个代码
import re
str1 = "These should be counted as a single-word, b**m !?"
match_pattern = re.findall(r'\w{1,15}', str1)
print(match_pattern)
我希望输出是:
['These', 'should', 'be', 'counted', 'as', 'a', 'single-word', 'b**m']
输出应排除非单词,例如“!?”我应该使用哪些其他验证来匹配并实现所需的输出?
【问题讨论】:
-
非正则表达式解决方案:
str1.strip(string.punctuation).replace(',','').split()
标签: python regex python-3.x