import re


def create_regex_function(body):
    """
    Create function from regex pattern.
    
    It is used for creating a function for classification.

    Args:
        body (string): A regex pattern

    Returns:
        function: A function which will return string for classification
    """
    pattern = re.compile(body)
    def fn(data):
        filename = data[0]
        m = pattern.search(filename)
        if m and len(m.groups()) > 0:
            # use a first group if there are any groups
            return m.group(1)
        elif m:
            # use entire match
            return m.group()
        # no mathced text found
        return filename
    return fn