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])];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With