cocoa - Regex too greedy; eats nearly all my rows -
from xml-data:
<row a1:height="17" ss:styleid="s139"> <cell ss:styleid="s69"><data ss:type="string">title1</data><namedcell ss:name="print_titles"/><namedcell ss:name="_filterdatabase"/><namedcell ss:name="print_area"/></cell> <cell ss:styleid="s70"><data ss:type="string">title2</data><namedcell ss:name="print_titles"/><namedcell ss:name="_filterdatabase"/><namedcell ss:name="print_area"/></cell> </row> <row a2:height="17" ss:styleid="s139"> <cell ss:styleid="s69"><data ss:type="string">title1</data><namedcell ss:name="print_titles"/><namedcell ss:name="_filterdatabase"/><namedcell ss:name="print_area"/></cell> <cell ss:styleid="s70"><data ss:type="string">title2</data><namedcell ss:name="print_titles"/><namedcell ss:name="_filterdatabase"/><namedcell ss:name="print_area"/></cell> </row> ....
using regex i'm trying find first row contains cells "title1" , "title2" in it.
-(nsstring *)extractdatafromxmlstring:(nsstring *)xmlstring{ nsstring *headerpattern = @" *<row[^>]*>\n" @" *<cell[^>]*>.*title1.*</cell>\n" @" *<cell[^>]*>.*title2.*</cell>\n" @" *</row>"; nserror *error = null; nsregularexpression *headerexpression = [nsregularexpression regularexpressionwithpattern:headerpattern options:nsregularexpressioncaseinsensitive|nsregularexpressiondotmatcheslineseparators error:&error]; nsrange rangeoffirstmatch = [headerexpression rangeoffirstmatchinstring:xmlstring options:0 range:nsmakerange(0, [xmlstring length])] return [xmlstring substringwithrange:rangeoffirstmatch] }
however entire string returned can me?
replacing .*
.*?
in pattern should trick, though should consider using actual xml parser instead of regular expressions this.
Comments
Post a Comment