我设法找到了以大写字母开头的单词,但找不到正则表达式来过滤掉从句子开头开始的单词。每个句子都以句号和空格结尾。测试字符串 = This is a Test sentence. The sentence is Supposed to Ignore the Words at the beginning of the Sentence.期望输出 = ['Test', 'Supposed', 'Ignore', 'Words', 'Sentence']我正在用 Python 编码。如果有人可以帮助我解决正则表达式,我会很高兴:)
2 回答
慕丝7291255
TA贡献1859条经验 获得超6个赞
您可以使用以下表达式:
(?<!^)(?<!\. )[A-Z][a-z]+
正则表达式演示在这里。
import re
mystr="This is a Test sentence. The sentence is Supposed to Ignore the Words at the beginning of the Sentence."
print(re.findall(r'(?<!^)(?<!\. )[A-Z][a-z]+',mystr))
印刷:
['Test', 'Supposed', 'Ignore', 'Words', 'Sentence']
添加回答
举报
0/150
提交
取消