Return the geometry and attributes of a shapefile whose fields match a regular expression given

    :param sf: shapefile
    :type sf: shapefile object
    :regex: regular expression to match
    :type regex: string
    :field: field number to be matched with the regex
    :type field: integer

def string_match(sf,regex,field=2):
    """
    Return the geometry and attributes of a shapefile whose fields match a regular expression given

    :param sf: shapefile
    :type sf: shapefile object
    :regex: regular expression to match
    :type regex: string
    :field: field number to be matched with the regex
    :type field: integer
    """
    index = []
    shape_records = []
    for rec in enumerate(sf.shapeRecords()):
        m = re.search(regex,rec[1].record[field])
        if m is not None:
            index.append(rec[0])
            shape_records.append(rec[1])
    return index,shape_records