import re


def extractexclude(l, regexp):
    """
    Take a text line, and check for the regexp, which is supposed to have one defined group.
    Extract the group if possible: if so, remove the entire regexp from the
    line and return (newline without regexp, group(1))
    If not, just return (l,None)

    This is useful for extracting values from "var=value" type strings and then
    removing them form the source string.
    """
    match = re.search(regexp,l)
    if match:
        res = match.group(1)
        # print l
        # print match.start()
        # print match.end()
        # print res
        newline = l[:match.start()] + l[match.end():]
        return (newline,res)
    else:
        return (l, None)