第42月第18天 iOS匹配特殊字符

1.

- (BOOL)checkSpecialCharacter:(NSString *)string
{
    NSString *regex = @"[`~!@#$^&*()=|{}‘:;‘,\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“‘。,、?]+";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    return [pred evaluateWithObject:string];
}

  https://www.jianshu.com/p/88be28860cde

    __block BOOL isMatch = NO;
    NSString *letters = @"(  ????????  )?(?﹏?)??(•?? ? ??•??)?_(___°π°œ)_「」°?|_|_=3( ´???` )*/ω\*)£";
    [letters enumerateSubstringsInRange:NSMakeRange(0, [letters length])
                                options:(NSStringEnumerationByComposedCharacterSequences)
                             usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
        if ([string containsString:substring]) {
            NSLog(@"match character:%@",substring);
            isMatch = YES;
            *stop = YES;
        }
    }];
    
    if (!isMatch) {
        NSString *pattern = @"[`~!@#$^&*()=|{}‘:;‘,\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“‘。,、?]+";
        NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
        isMatch = [pred evaluateWithObject:string];
    }
    NSLog(@"%@ is SpecialCharacters:%d",string,isMatch);

 

第42月第18天 iOS匹配特殊字符

上一篇:主流程序员的绝佳选择?三个选择使用 Go 语言的理由


下一篇:django执行迁移命令时报错django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.