Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
218 views
in Technique[技术] by (71.8m points)

python - How can I use regex in django's Replace function

I'm trying to update all urls in my query by using django's update and Replace function using regex. Here's what I've tried so far but it seems like django's Value expression did not recognize my regex.

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/')))

My goal is to remove all numbers after /some-link/ (e.g. /some-link/55/test to just /some-link/test)

question from:https://stackoverflow.com/questions/65838311/how-can-i-use-regex-in-djangos-replace-function

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...