我试着用关于芬德尔在我的文本栏中,找到以下两个两边都有空格的选项,因为这是唯一重要的。我使用以下脚本
url = '#MnA deals for 2015 across all #oilandgas sectors were lower than WAR WARduring the CFO Great CIO Recession'
regex=re.findall(r'WAR|CIO|CISO|CTO|C-Suite|CMO|CFO|Founder+',url)
print regex
['WAR', 'WAR', 'CFO', 'CIO']
而不是这个我只想要
^{pr2}$从第二次开始,这不仅仅是战争,更是一场战争,我不想那样
还有什么是运算符来得到我想在下标前面看到的所有东西,比如
['WAR', 'WARduring','CFO', 'CIO']
感谢每一个帮助
方法一:错误地将战争视为战争
另一种方法:使用\b仅分隔单词
在正则表达式中使用单词boundary [Know more]将解决您的问题
正则表达式
代码
^{pr2}$您可以使用展望:
(?=\s|$)
将断言关键字后是否存在空格或行尾。在对于第二个任务,请使用以下正则表达式:
^{pr2}$这里
\w*
后的关键字将匹配0个或多个单词字符。在相关问题 更多 >
编程相关推荐