def text_filter(regex_base, value):
    """
    Helper method to regex replace images with captions in different markups
    """
    regex = regex_base % {
        're_cap': r'[a-zA-Z0-9\.\,:;/_ \(\)\-\!\?"]+',
        're_img': r'[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 % { 're_cap' : r'[a-zA-Z0-9\.\,:;/_ \(\)\-\!\?"]+' , 're_img' : r'[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