Regular Expression Replace Template Filter

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import re 

from django import template
register = template.Library()

@register.filter
def replace ( string, args ): 
    search  = args.split(args[0])[1]
    replace = args.split(args[0])[2]

    return re.sub( search, replace, string )

More like this

  1. @reply links in Twitter messages by ryanberg 3 years, 7 months ago
  2. Template tag "ifregex" and "ifnotregex" by arthurfurlan 2 years, 8 months ago
  3. Cheap direct_to_tempalte patterns by jjdelc 3 years, 2 months ago
  4. Use MEDIA_URL in flatpages by robhudson 3 years, 10 months ago
  5. in_group template filter by whiteinge 3 years, 7 months ago

Comments

(Forgotten your password?)