Python 正则表达式 :combining re pattern format with a variable

标签 python regex

我想结合一个 python 变量和模式。我该怎么做?

下面是我想做的。

re.search(r'**some_variable+pattern**',str_for_pattern_match,flags)

感谢您的帮助。

最佳答案

通常的字符串格式化方式效果很好

re.search(r'**%s+pattern**' % some_variable, str_for_pattern_match, flags)

关于Python 正则表达式 :combining re pattern format with a variable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8667454/

相关文章:

python - 如何迭代元组或函数列表并对其返回值进行操作?

regex - 正则表达式是逻辑编程的一个例子吗?

regex - PostgreSQL 检查约束不起作用

python - 在不减少总数的情况下删除列表的项目

python - 现有演示文稿中每张 pptx 幻灯片的形状编号/索引

安卓正则表达式

python - 合并多个正则表达式以进行日期识别

java - 如何删除字符串中的括号字符(java)

Python单元测试多个输入

python - 光束/数据流 Python : AttributeError: '_UnwindowedValues' object has no attribute 'sort'