def text_filter(regex_base, value):
 regex = (regex_base % {u're_cap': u'[a-zA-Z0-9\\.\\,:;/_ \\(\\)\\-\\!\\?"]+', u're_img': u'[a-zA-Z0-9\\.:/_\\-\\% ]+'})
 images = re.findall(regex, value)
 for i in images:
  image = i[1]
  if image.startswith(settings.MEDIA_URL):
   image = image[len(settings.MEDIA_URL):]
  im = get_thumbnail(image, str(sorl_settings.THUMBNAIL_FILTER_WIDTH))
  value = value.replace(i[1], im.url)
 return value

def text_filter ( regex_base , value ) : regex = ( regex_base % { u're_cap' : u'[a-zA-Z0-9\\.\\,:;/_ \\(\\)\\-\\!\\?"]+' , u're_img' : u'[a-zA-Z0-9\\.:/_\\-\\% ]+' } ) images = re . findall ( regex , value ) for i in images : image = i [ 1 ] if image . startswith ( settings . MEDIA_URL ) : image = image [ len ( settings . MEDIA_URL ) : ] im = get_thumbnail ( image , str ( sorl_settings . THUMBNAIL_FILTER_WIDTH ) ) value = value . replace ( i [ 1 ] , im . url ) return value
helper method to regex replace images with captions in different markups .