'To use this function, simply pass a list of tuples of the form:
(string/regex_to_match,html_to_inject)
NOTE: Matching will be case insensitive unless differnt flags are given
The pre array will have the match in front of your injected code, the post
will put the match behind it.'

def _insert_html(self, data, pre=[], post=[], re_flags=re.I):

    pre_regexes = [re.compile((('(?P<match>' + i[0]) + ')'), re_flags) for i in pre]
    post_regexes = [re.compile((('(?P<match>' + i[0]) + ')'), re_flags) for i in post]
    for (i, r) in enumerate(pre_regexes):
        data = re.sub(r, ('\\g<match>' + pre[i][1]), data)
    for (i, r) in enumerate(post_regexes):
        data = re.sub(r, (post[i][1] + '\\g<match>'), data)
    return data
