import re


def convert_RL_name(name):
    """Switch R-L or L-R presceding, following or in-between underscores

    Args:
        name(str): String to operate on
    Returns:
        str: Switched name

    Example:
        _L -> _R /  _L0_ -> _R0_ / L_ > R_ ...
    """

    # If the input is just L or R return the converted
    if name == "L":
        return "R"
    elif name == "R":
        return "L"

    # Creates pattern
    re_str = "_[RL][0-9]+_|^[RL][0-9]+_|_[RL][0-9]+$|_[RL]_|^[RL]_|_[RL]$"
    re_pattern = re.compile(re_str)

    # Search for matches
    re_match = re.search(re_pattern, name)

    # Returns unchanged name if nothing matches
    if not re_match:
        return name

    instance = re_match.group(0)
    if instance.find("R") != -1:
        rep = instance.replace("R", "L")
    else:
        rep = instance.replace("L", "R")

    name = re.sub(re_pattern, rep, name)
    return name