Regex Categories 是一款为 NSRegularExpression 和 NSString 采集 objective-c 类别的工具,使他们可用性更高更简洁。
//Using NSRegularExpression NSString* string = @"I have 2 dogs."; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\d+" options:NSRegularExpressionCaseInsensitive error:&error]; NSTextCheckingResult *match = [regex firstMatchInString:string options:0 range:NSMakeRange(0, [string length])]; BOOL isMatch = match != nil; // Using this library BOOL isMatch = [@"I have 2 dogs." isMatch:RX(@"\\d+")];