Mick Walker Mick Walker - 17 days ago 5x
Objective-C Question

Objective-C - Finding a URL within a string

Given a large string, what is the best way to create an array of all valid urls which are contained within the string?


No need to use RegexKitLite for this, since iOS 4 Apple provide NSDataDetector (a subclass of NSRegularExpression).

You can use it simply like this (source is your string) :

NSDataDetector* detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
NSArray* matches = [detector matchesInString:source options:0 range:NSMakeRange(0, [source length])];