2017-12-27 98 views
1

在字符串中,我想使用re模块查找长度大于4的所有单词。regx找到python 3.x中超过4个单词的单词

样品输入:This is good Python forum and its helping a lot to beginners.

输出:['Python','helping','beginners]

下面我试过,但它不工作:

match=re.findall(r'([\w]{4}).*',str1) 
+1

请编辑包括到目前为止您已经尝试了所有步骤,Stack Overflow是不是代码写作服务。 –

回答

2

查找其长度大于

所有单词

用下面的办法:

import re 

s = 'This is good Python forum and its helping a lot to beginners.' 
result = re.findall(r'\w{5,}', s) 

print(result) 

输出:

['Python', 'forum', 'helping', 'beginners'] 
+0

谢谢!这是如此简单,我正在寻找lookahead和断言。所以愚蠢我是:( – vickey99

相关问题