def string_match(sf,regex,field=<NUM_LIT:2>):
index = []<EOL>shape_records = []<EOL>for rec in enumerate(sf.shapeRecords()):<EOL><INDENT>m = re.search(regex,rec[<NUM_LIT:1>].record[field])<EOL>if m is not None:<EOL><INDENT>index.append(rec[<NUM_LIT:0>])<EOL>shape_records.append(rec[<NUM_LIT:1>])<EOL><DEDENT><DEDENT>return index,shape_records<EOL>
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