def _regex_to_postfix(regex):
    """
    Convert infix regular expression into postfix w/ implicit concatenation.

    Parameters
    ----------
    regex : str
        Regular expression -- accepts only ( | ) * + ?

    Returns
    -------
    str

    Notes
    -----
    Translated from Russ Cox's C implementation of
    Ken Thompson's Regular Expression Search Algorithm:
    https://swtch.com/~rsc/regexp/dfa0.c.txt (MIT License)

    See also http://swtch.com/~rsc/regexp/ and
    Thompson, Ken.  Regular Expression Search Algorithm,
    Communications of the ACM 11(6) (June 1968), pp. 419-422.

    """
    nalt = 0
    natom = 0
    dst = []
    paren = []
    if not len(regex) > 0:
        raise ValueError('Regular expression is empty.')
    for _ in regex:
        if _ == '(':
            if natom > 1:
                natom = natom - 1
                dst.append('.')
            paren.append((nalt, natom))
            nalt = 0
            natom = 0
        elif _ == '|':
            if natom == 0:
                raise ValueError('Regex is missing an expression before |.')
            natom -= 1
            while natom > 0:
                dst.append('.')
                natom -= 1
            nalt += 1
        elif _ == ')':
            if not paren:
                raise ValueError('Regex parentheses do not match.')
            if natom == 0:
                raise ValueError('Regex parentheses are missing an expression.'
                    )
            natom -= 1
            while natom > 0:
                dst.append('.')
                natom -= 1
            while nalt > 0:
                dst.append('|')
                nalt -= 1
            nalt, natom = paren.pop()
            natom += 1
        elif _ in ('*', '+', '?'):
            if natom == 0:
                raise ValueError(
                    'Regex operator %s requires an expression.' % _)
            dst.append(_)
        else:
            if natom > 1:
                natom -= 1
                dst.append('.')
            dst.append(_)
            natom += 1
    natom -= 1
    while natom > 0:
        dst.append('.')
        natom -= 1
    while nalt > 0:
        dst.append('|' * nalt)
        nalt -= 1
    return ''.join(dst)
