Skip to content

Instantly share code, notes, and snippets.

Created Apr 5, 2013
What would you like to do?
Taken from 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]) {
[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