到目前为止我有这个代码:
def find_words(m_count, m_string):
m_list = re.findall(r'\w{6,}', m_string)
return m_list
有没有办法使用 m_count
而不是显式使用计数 (6)?
最佳答案
将 int 转换为字符串并添加到您的 reg exp 中,如下所示:
def find_words(m_count, m_string):
m_list = re.findall(r'\w{'+str(m_count)+',}', m_string)
return m_list
关于Python,正则表达式动态计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39043494/