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 4 years, 10 months ago
  2. Cheap direct_to_tempalte patterns by jjdelc 4 years, 6 months ago
  3. keywords arguments parser for custom template tags by bruno 4 years, 4 months ago
  4. Login Required Middleware by onecreativenerd 4 years, 6 months ago
  5. Login Required Middleware with Next Parameter by bernardoporto 6 months, 1 week ago

Comments

(Forgotten your password?)