[英]Python-Mysql REGEXP with variable
I can do a regular variable substitution in mysql/python using:我可以使用以下方法在 mysql/python 中进行常规变量替换:
cursor.execute("SELECT DATE_FORMAT(`item_start`,'%%Y-%%m') AS ym,
count(*) as num
from t_calendar_data
where Concat(item_subject, ' ', item_text_body) like %s
group by ym",
("%{}%".format(i),))
but I'm not sure how to use REGEXP with:但我不确定如何将 REGEXP 用于:
[[:<:]]VARIABLE[[:>:]]
I've tried various forms of:我尝试了各种形式:
cursor.execute("SELECT DATE_FORMAT(`item_start`,'%%Y-%%m') AS ym,
count(*) as num from t_calendar_data where Concat(item_subject, ' ',
item_text_body) REGEXP %s group by ym", ("[[:<:]]%{}%
[[:>:]]".format(i),))
with no success.没有成功。 How do I wrap the regex (assuming I'm putting REGEXP in the correct spot)?
我如何包装正则表达式(假设我将 REGEXP 放在正确的位置)?
Wiktor's response worked perfect. Wiktor 的反应很完美。 I had to remove my extra %.
我不得不删除我额外的 %。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.