给定一个大字符串,创建包含字符串中所有有效 url 的数组的最佳方法是什么?
最佳答案
不需要为此使用 RegexKitLite
,因为 iOS 4 Apple 提供了 NSDataDetector
(NSRegularExpression
的子类)。
你可以像这样简单地使用它(source
是你的字符串):
NSDataDetector* detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
NSArray* matches = [detector matchesInString:source options:0 range:NSMakeRange(0, [source length])];
关于iphone - Objective-C - 在字符串中查找 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5998969/