Regex – Using regular expression in Django templates

djangodjango-templatesregex

I wonder if it is possible using regular expression in Django templates:

<a href="#{{form.deal_template_name.value}} ????" data-toggle="tab">{{form.deal_template_name.value}}</a>

I would like to replace both spaces and dot's with _. (Otherwise the link would have trouble with the target)

{{form.deal_template_name.value}}

.replace(/ /g,"_").replace(/\./g,"_")

How to do that though in template directly, is that possible?

Best Answer

If you really want to shoot yourself in the foot:

Custom django filter that does that:

{% load replace %} {{ mystring|replace:"/l(u+)pin/m\1gen" }}