背景:
运营颜色配置错误,导致客户端显示异常,全覆盖法:
NSString *CheckColorStr(NSString *str) {
if (!str.length) {
return @"";
}
NSString *pattern = @"([A-Fa-f0-9]+)";
NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:pattern options:0 error:nil];
NSArray *regexArray = [regex matchesInString:str options:0 range:NSMakeRange(0, str.length)];
if (!regexArray.count) {
return @"";
}
NSString *string = @"";
for (NSTextCheckingResult*checkResult in regexArray) {
string = [string stringByAppendingString:[str substringWithRange:checkResult.range]];
if (string.length >= 8) {
break;
}
}
NSLog(@"___________string:%@", string);
if (string.length >= 8) {
return [string substringToIndex:8];
}else if (string.length >= 6){
return [string substringToIndex:6];
}else {
return @"";
}
}