import re


def rle2cells(rle_str: str) -> str:
    """Convert lifeform string in RLE encoding to PlainText

    Args:
        rle_str (str): single line of RLE commands

    Returns:
        str: valid PlainText-encoded lifeform
    """
    # drop the last part
    if "!" in rle_str:
        rle_str = rle_str[: rle_str.index("!")]
    else:
        raise ValueError('Incorrect input: no "!"')

    if not set(rle_str).issubset("0123456789bo$"):
        raise ValueError("Incorrect input: wrong character set")

    commands = re.findall("([0-9]*)(b|o|\\$)", rle_str)
    if len(commands) == 0:
        raise ValueError("Incorrect input: wrong pattern format")

    layout_string = ""
    parse_dict = {"b": ".", "o": "O", "$": "\n"}
    for com in commands:
        n = int(com[0]) if com[0] else 1
        layout_string += parse_dict[com[1]] * n

    return layout_string