该项目使正则表达式在Objective-C中变得简单。以下是一个示例,其中四行代码变成了一行。
```// 在此库中不使用此库 NSString* string = @"I have 2 dogs."; NSRegularExpression *regex = [NSRegularExpression regular ExpressionWithPattern:@"\d+" options:NSRegularExpressionCaseInsensitive error:&error]; NSTextCheckingResult *match = [regex firstMatchInString:string options:0 range:NSMakeRange(0, [string length])]; BOOL isMatch = match != nil;```
```// 使用此库 BOOL isMatch = [@"I have 2 dogs." isMatch:RX(@"\d+")];```
pod 'RegExCategories'
Josh Wright