没有匹配的====================================================
我知道,这是“空白”的问题,如果我在"https“前面添加空白,那么它就能工作了。那么NSDataDetector不能解决这个问题吗?
NSString *originString = @"【mans】下单立减5.00元https://kdt.im/uYMI4r";
NSDataDetector *linkDetector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
NSArray *matches1 = [linkDetector matchesInString:originString options:0 range:NSMakeRange(0, [originString length])];
for (NSTextCheckingResult *match in matches1) {
if ([match resultType] == NSTextCheckingTypeLink) {
NSURL *url = [match URL];
}
}发布于 2016-10-11 06:10:34
NSDataDetector的一个已知问题是,如果协议之前有一个空格(即http://或https:// ),那么它可以工作,否则就不能工作。
例如:
let input = "This is a test with the URL https://www.sharpkits.com to be detected."
let detector = try! NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
let matches = detector.matches(in: input, options: [], range: NSRange(location: 0, length: input.utf16.count))
for match in matches {
let url = (input as NSString).substring(with: match.range)
print(url)
}对于let https://www.sharpkits.com=“这是要检测到的URL的测试。”
输出: URLhttps://www.sharpkits.com
所以不能用NSDataDetector
https://stackoverflow.com/questions/39970947
复制相似问题