我想打印字符串中匹配单词的10个单词前后
例如,我有
string = "About the company -Our client is one of the world's fastest-growing AI-based contract management solution providers.Exp -7+ Years Location -MumbaiJob Role -Min 7years hands-on experience in Natural Language Processing, Machine Learning, Artificial Intelligence, and IBM Watson"
在上面的字符串中,我想搜索字母体验,并希望输出如下
Location -MumbaiJob Role -Min 7years hands-on experience in Natural Language"
我尝试了(\S+)\s+exp+
,但它只返回单词前面的一个
在一个或多个空白字符上拆分单词可能是最好的方法:
印刷品:
但如果您坚持使用正则表达式,则应在“经验”之前打印最多5个单词,在“经验”之后打印最多5个单词:
印刷品:
更新以处理“体验”或“体验”
我还简化了正则表达式:
印刷品:
请尝试下面的正则表达式
这里
\1
前面有10个单词\3
后面有10个单词在“经验”之后Demo
您可以先用空格分隔单词,然后从列表的前10个单词中选择,直到列表的末尾,最后将此列表分组以重做字符串
相关问题 更多 >
编程相关推荐