def grp(pattern, name=None):
    """
    Grouping. Defines a group with a given name and containing pattern.

    :param name:
        Name of the group which can be used to get the content of the group
        after matching. By default the group does not have a name.
    """
    if name is None:
        return '(?:%s)' % pattern
    else:
        return '(?P<%s>%s)' % (name, pattern)