Correctly use the regex replacement function to substitute all urls in a particular chunk of text

This commit is contained in:
Calen Pennington
2012-05-18 11:26:42 -04:00
parent 092247fd2a
commit d0172d5d28

View File

@@ -5,14 +5,14 @@ PREFIX = '/static/'
STATIC_PATTERN = re.compile(r"""
(?P<quote>['"]) # the opening quotes
{prefix} # the prefix
.*? # everything else in the url
(?P<rest>.*?) # everything else in the url
(?P=quote) # the first matching closing quote
""".format(prefix=PREFIX), re.VERBOSE)
PREFIX_LEN = len(PREFIX)
def replace(static_url):
quote = static_url[0]
url = staticfiles_storage.url(static_url[1+PREFIX_LEN:-1])
quote = static_url.group('quote')
url = staticfiles_storage.url(static_url.group('rest'))
return "".join([quote, url, quote])
def replace_urls(text):