Novarg
Novarg

Reputation: 7440

rewriting NSRegularExpression to RegexKit

I'm quite new to Mac OS X development(just my second day). Did a couple months of iOS programming, got the basics, made a small app. Then I decided to make it also for Mac OS X when I suddenly encountered a problem: NSRegularExpression is only supported by Mac OS X 10.7 or later and I'm using 10.6.7. After a bit of googling I found a RegexKit.framework. So I installed it, but then I gotta rewrite this piece of code for RegexKit framework.

NSString *aString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSError *error = nil;
NSRegularExpression *regex = [NSRegularExpression         
                              regularExpressionWithPattern:@"(\\{.*?\\})"
                              options:NSRegularExpressionCaseInsensitive
                              error:&error];
[regex enumerateMatchesInString:aString options:0 range:NSMakeRange(0, [aString length]) usingBlock:^(NSTextCheckingResult *match, NSMatchingFlags flags, BOOL *stop){
    [MyParserClass parserWithResponse:[aString substringWithRange:match.range] delegate:self andRequest:request];
}];

Any help on how can I do the same thing by using RegexKit would be appreciated.

edit: got it working that way:

NSString *aString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSString *regex = @"(\\{.*?\\})";
NSArray *matches = [aString arrayOfCaptureComponentsMatchedByRegex:regex];
for (NSArray *match in matches) {
    [MyParserClass parserWithResponse:[match lastObject] delegate:self andRequest:request];
}

hopefully it will help somebody someday :)

Upvotes: 1

Views: 697

Answers (1)

Novarg
Novarg

Reputation: 7440

got it working that way:

NSString *aString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSString *regex = @"(\\{.*?\\})";
NSArray *matches = [aString arrayOfCaptureComponentsMatchedByRegex:regex];
for (NSArray *match in matches) {
    [MyParserClass parserWithResponse:[match lastObject] delegate:self andRequest:request];
}

hopefully it will help somebody someday :)

Upvotes: 3

Related Questions