import re


def match_numbered_leaf(leaf_to_match, search_string):
    """
    Find a numbered leaf matching a tf.Operation and return it if found.

    Example: 'Conv2D' will match '.../Conv2D_5' and return 'Conv2D_5'
    """
    expr = '/({0})|/({0}_[0-9]+)'.format(leaf_to_match)
    match = re.search(expr, search_string)
    if match is not None:
        return match.group(1)