特殊字符正则表达式查询

前端之家收集整理的这篇文章主要介绍了特殊字符正则表达式查询前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

个人随笔记录:


- (NSMutableAttributedString *)filterLinkWithContent:(NSString *)content {
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:content];
    NSError *error = NULL;
    NSRegularExpression *regularExpression = [NSRegularExpression regularExpressionWithPattern:@"https://\\w+" options:0 error:nil];
    NSDataDetector *detector =
    [NSDataDetector dataDetectorWithTypes:(NSTextCheckingTypes)NSTextCheckingTypeLink | NSTextCheckingTypePhoneNumber | NSTextCheckingTypeDate
                                    error:&error];
    NSArray *matches = [regularExpression matchesInString:content
                                         options:0
                                           range:NSMakeRange(0,[content length])];
    for (NSTextCheckingResult *match in matches) {
        NSLog(@"----%@",match);
        if (match.range.location != NSNotFound)
        {
            [attributedString addAttribute:NSLinkAttributeName value:[content substringWithRange:match.range] range:match.range];
        }
        if (([match resultType] == NSTextCheckingTypeDate)) {
            
            NSDate *url = [match date];
            [attributedString addAttribute:NSLinkAttributeName value:url range:match.range];
        }
    }
    return attributedString;
}
原文链接:https://www.f2er.com/regex/360831.html

猜你在找的正则表达式相关文章