Skip to content

Instantly share code, notes, and snippets.

@xr1337

xr1337/gist:5318147

Created Apr 5, 2013
Embed
What would you like to do?
Taken from https://gist.github.com/iangmaia/3368412 and added an ignore to certain URL schemes such as mailto
- (NSArray *) extractLinksFromString:(NSString*)txt ignoreSchemes:(NSArray*)ignoreSchemes{
NSError *error = NULL;
NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:&error];
if (error) return nil;
NSArray *linkMatches = [detector matchesInString:txt options:0 range:NSMakeRange(0, txt.length)];
NSMutableArray *result = [NSMutableArray arrayWithCapacity:[linkMatches count]];
for (NSTextCheckingResult *match in linkMatches) {
if ([match resultType] == NSTextCheckingTypeLink) {
if ([ignoreSchemes containsObject:match.URL.scheme]) {
continue;
}
[result addObject:[[match URL] absoluteString]];
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment