特殊字符正则表达式查询

个人随笔记录:


- (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;
}

相关文章

正则替换html代码中img标签的src值在开发富文本信息在移动端...
正则表达式
AWK是一种处理文本文件的语言,是一个强大的文件分析工具。它...
正则表达式是特殊的字符序列,利用事先定义好的特定字符以及...
Python界一名小学生,热心分享编程学习。
收集整理每周优质开发者内容,包括、、等方面。每周五定期发...