def fmt_search(value, search_match):
 if search_match:
  caseless = re.compile(re.escape(search_match), re.IGNORECASE)
  for variation in re.findall(caseless, value):
   value = re.sub(caseless, u'<span class="hlmatch">{0}</span>'.format(variation), value)
 return value

def fmt_search ( value , search_match ) : if search_match : caseless = re . compile ( re . escape ( search_match ) , re . IGNORECASE ) for variation in re . findall ( caseless , value ) : value = re . sub ( caseless , u'<span class="hlmatch">{0}</span>' . format ( variation ) , value ) return value
formats search match .