best_filters.resub

best_filters.resub(str, arg)

regex substitute a substring

The substitution syntax is : <chosen separator><regex pattern to search><separator><replacement string>

Examples

>>> c = {'mystr':'hello world'}
>>> t = '{% load best_filters %}{{ mystr|resub:"/ .*/ eric" }}'
>>> Template(t).render(Context(c))
'hello eric'
>>> c = {'mypath':'/home/theuser/projects'}
>>> t = r'''{% load best_filters %}
... {{ mypath|resub:",/home/([^/]*)/projects,login=\1" }}'''
>>> Template(t).render(Context(c))
'\nlogin=theuser'