[英]In python, how can I use regex to replace square bracket with parentheses
[英]How can I use regex in django's Replace function
我正在尝试使用 django 的update
查询中的所有 url,并使用正则表达式Replace
function。 这是我到目前为止尝试过的,但似乎 django 的Value
表达式无法识别我的正则表达式。
from django.db.models import Value
from django.db.models.functions import Replace
Foo.objects.filter(
some_url__iregex=r'^\/some-link\/\d+\/').update(
some_url=Replace(
'some_url', Value(r'^\/some-link\/\d+\/'),
Value('/some-link/')))
我的目标是删除/some-link/
之后的所有数字(例如/some-link/55/test
到只是/some-link/test
)
I wasn't able to get the Replace
function from Django working, but I was able to use the Function for REGEXP_REPLACE
detailed in this answer: https://stackoverflow.com/a/68402017/3056056
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.