Python,正则表达式动态计数

标签 python regex

到目前为止我有这个代码:

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/

相关文章:

python - 负坐标对 cv2.perspectiveTransform 意味着什么?

python - SQLAlchemy的反射工具可以输出python源码吗?

regex - HTACCESS重写: Ignore another rewrite rule

java - 使用 Java 正则表达式查找具有任意数量嵌套的函数

java - 匹配特定字符前后的正则表达式

JavaScript RegExp 包括模式中的标志

python - 在 Python 中导入时 Matplotlib 未被识别为模块

python - 如何使用 Cython 加速 python 中的 for 循环

Python 测试嵌套 json - 列表索引超出范围错误

javascript - jQuery 正则表达式搜索 - 存储所有变量名称