def getfields( fields, afile, lower=True ):
    """ grep lines starting with given keywords / field names ":"
        e.g. "name version".split()
       -> lines [ ("name", "name: ...") ... ]
    """
    if isinstance( fields, basestring ):
        fields = filter( None, re.split( r"[\s:,]+", fields ))
    matchf = matcher( fields )
    if isinstance( afile, basestring ):
        afile = open( afile )
    lines = []
    for line in afile:
        m = _kw_re.match( line )  # kw: ...
        if not m:
            continue
        kw = m.group( 1 )
        if lower:  kw = kw.lower()
        if matchf( kw ):  # kw in dict list tuple or set  or func( kw )
            lines.append( (kw, line.rstrip()) )
    return lines
 grep lines starting with given keywords / field names ":"
        e.g. "name version".split()
       -> lines [ ("name", "name: ...") ... ]
    
recipes/Python/576741_uniform_matcher_re_pattern__re__func__dict_/recipe-576741.py