fuz*_*oat 4 iphone cocoa-touch objective-c ios nsregularexpression
有没有办法NSRegularExpression指定您想要进行区分大小写的搜索?我试图在下面的文本中匹配大写TAG"ACL".我使用的模式很简单:
// Pattern
[A-Z]+
// SearchText
<td align=\"left\" nowrap><font face=\"courier, monospace\" size=\"-1\">ACL*</font></td>
// Code:
NSString *textBuffer = @"<td align=\"left\" nowrap><font face=\"courier, monospace\" size=\"-1\">ACL*</font></td>";
NSString *pattern = @"([A-Z]+)";
NSRegularExpression *regExp = [NSRegularExpression regularExpressionWithPattern:pattern options:NSRegularExpressionCaseInsensitive error:nil];
NSTextCheckingResult *result = [regExp firstMatchInString:textBuffer options:0 range:NSMakeRange(0, [textBuffer length])];
NSLog(@"OBJECT CLASS: %@", [textBuffer substringWithRange:[result range]]);
Run Code Online (Sandbox Code Playgroud)
输出:(使用case-Insensative我按预期获得第一个"td",当我真正想要的是"ACL"时
我知道那NSRegularExpressionCaseInsensitive是错的,我希望会有一个NSRegularExpressionCaseSensitive.还有一个flagOption ?(i),它还指定了一个不区分大小写的搜索,但同样没有任何案例敏感的搜索.我错过了什么?