生僻字的另一种判断方式

2023-07-13  本文已影响0人  Fendouzhe
- (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;
}
上一篇 下一篇

猜你喜欢

热点阅读