djangosnippets.org: Latest snippets tagged with 'regular-expressions'https://djangosnippets.org/tags/regular-expressions/2007-02-28T22:07:59.753069-06:00Regular Expression Replace Template Filter
2007-02-28T22:07:59.753069-06:00joshuahttps://djangosnippets.org/snippets/60/<p>This will perform a regular expression search/replace on a string in your template.</p>
<p><code>{% load replace %}</code>
<code>{{ mystring|replace:"/l(u+)pin/m\1gen" }}</code></p>
<p>If:
<code>mystring = 'lupin, luuuuuupin, and luuuuuuuuuuuuupin are lè pwn'</code> then it will return:
<code>mugen, muuuuuugen, and muuuuuuuuuuuuugen are lè pwn</code></p>
<p>The argument is in the following format:</p>
<pre><code>[delim char]regexp …</code></pre>
Freely redistributable