import re


def join_lines(src, before, after, sep=" "):
    """
    Remove the newline and indent between a pair of lines where the first
    ends with ``before`` and the second starts with ``after``, replacing
    it by the ``sep``.
    """
    before_re = "][".join(before).join("[]")
    after_re = "][".join(after).join("[]")
    regex = "\n\\s*".join([before_re, after_re])
    return re.sub(regex, sep.join([before, after]), src)