いくつかの XML データから:
<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>
....
正規表現を使用して、「Title1」と「Title2」を含むセルを含む最初の行のみを見つけようとしています。
-(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]
}
ただし、文字列全体が返されます誰か助けてもらえますか?