def attr(name, grp=True):
    """Return a regular expression to match an XML attribute.
    
    name: name of the attribute to match
    grp: boolean indicating whether to retain the attribute value subgroup.
    returns: regular expression text
    """
    return '(?: +{0}="({1}[^"]+)")'.format(name, "" if grp else "?:")