Mick Walker Mick Walker - 1 year ago 108
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?

Answer Source

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])];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download