生僻字的另一种判断方式

- (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;
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容