import re


def _merge_string(a, b):
    """Merge strings ``a`` and ``b``.

       If a contains a substitution marker, e.g.:

           'content of {#} a'

       then b will be inserted at {#}.

       If b contains a hole, e.g.:

           'contents of {_} b'

       then a will be inserted at {_}.

       You cannot have both a substitution and a hole.
    """
    parent_re = re.compile(r'{#}')
    child_re = re.compile(r'{_}')
    if parent_re.search(b) and child_re.search(a):
        raise TypeError(
            "You cannot specify both a hole and a substitution %r, %r" % (
                a, b
            ))
    if parent_re.search(b):
        return parent_re.sub(a, b)
    if child_re.search(a):
        return child_re.sub(b, a)
    return b