import re


def substitute_name(pattern, name, left_side):
    """
    Replace substitutions in a name pattern.

    <name> will be replaced with the value of name.
    Patterns containing a pipe, eg.  <ABCD|EFGH>, will be replaced with "ABCD"
    if left_side is true or "EFGH" if left_side is false.
    """
    def sub(s):
        text = s.group(1)
        if text == 'name':
            return name

        if '|' in text:
            parts = text.split('|', 2)
            if left_side or len(parts) == 1:
                return parts[0]
            else:
                return parts[1]

        return s.group(0)
    return re.sub(r'<([^>]*)>', sub, pattern)