美文网首页
生僻字的另一种判断方式

生僻字的另一种判断方式

作者: Fendouzhe | 来源:发表于2023-07-13 14:45 被阅读0次
- (BOOL)containsUnCommonWord:(NSString *)content{
    if(!content.length) return NO;
    //过滤标点符号及常规字字符集,如果还存在字符串则默认含有生僻字
    NSString *pattern = @"[\\u0020-\\u007E\\u00A0-\\u00BE\\u4e00-\\u9fa5\\p{P}+\\p{S}]";
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:NSRegularExpressionCaseInsensitive error:nil];
    NSString *modifiedString = [regex stringByReplacingMatchesInString:content
                                                               options:0
                                                                 range:NSMakeRange(0, [content length])
                                                          withTemplate:@""];
    NSLog(@"modifiedString = %@ isMatch = %d",modifiedString,!!modifiedString.length);
    return !!modifiedString.length;
}

相关文章

网友评论

      本文标题:生僻字的另一种判断方式

      本文链接:https://www.haomeiwen.com/subject/xepmudtx.html