I’m trying to get all the XML out of certain tags (not just values but everything including more XML between two open and close tags) and I figured I’d use a regular expression.
My code looks like this
NSError *error2 = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"<PayloadPost>(.*)</PayloadPost>"
options:NSRegularExpressionCaseInsensitive
error:&error2];
if (error2)
{
NSLog(@"Error %@", [error2 description]);
}
NSArray *payloadRanges=[regex matchesInString:theXMLString options:0 range:NSMakeRange(0, [theXMLString length])];
int size=[payloadRanges count];
printf("Size %d",size);
Basically I need everything in the “PayloadPost”s and yet it keeps giving me nothing. I keep getting 0 for size and I know the XML has 3 instances in it.
Can anyone help me out?
make sure you set the multiline flag, https://developer.apple.com/library/mac/documentation/Foundation/Reference/NSRegularExpression_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSRegularExpressionDotMatchesLineSeparators
otherwise the ‘.’ character will not match the line break and your regex will match
but not