storing regexkitlite matches by by the group instead of the occurance
I'm not sure if there is away to do this but it doesnt hurt to ask i'm using regexkitlite to create a iPhone app. Im specifically using the Regex lib to parse some html. My question is in a regular expression such as @"<a href=([^>]*)>([^>]*) - "
each match in between the brackets can be placed in an array using
NSString *regexString = @"<a href=([^>]*)>([^>]*) - ";
NSArray *matchArray = [response arrayOfCaptureComponentsMatchedByRegex:regexString];
This stores the matches as :
Array ( Array(ENTIRE_MATCH1, FIRST_BRACKETS1, SECOND_BRACKETS1),
Array(ENTIRE_MATCH2, FIRST_BRACKETS2, SECOND_BRACKETS2),
Array(ENTIRE_MATCH3, FIRST_BRACKETS3, SECOND_BRACKETS3));
Is there a command that would allow be to capture the matches like this instead?
Array ( Array(ENTIRE_MATCH1, ENTIRE_MATCH2, ENTIRE_MATCH3),
开发者_如何学PythonArray(FIRST_BRACKETS1, FIRST_BRACKETS2, FIRST_BRACKETS3),
Array(SECOND_BRACKET1, SECOND_BRACKET2, SECOND_BRACKET3));
I know i could do this fairly easily with a for loops or for each loops but i was wondering if there is a function in the regexkitlite library.
Thanks in Advance,
Zen_Silence
If anyone else needs a function to copy a group to another array this look will do it i'm still looking for a better solution if someone has one.
group = [[NSMutableArray alloc] initWithCapacity:[matchArray count]];
for (int i = 0; i < [matchArray count]; i++) {
NSString *temp = [[matchArray objectAtIndex: i] objectAtIndex: 2];
[group addObject: temp];
}
精彩评论