Reputation: 26223
Is there a way using NSRegularExpression
to specify that you want to do a case-sensitive search? I am trying to match the upper-case TAG "ACL" in the text below. The pattern I am using is simply:
// 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]]);
Output: (with case-Insensative I am getting the first "td" as expected, when what I really want is "ACL"
I know that NSRegularExpressionCaseInsensitive
is wrong, I was hoping there would be a NSRegularExpressionCaseSensitive
. Also there is a flagOption ?(i)
that also specifies a case-insensitive search but again nothing for case-sensative. What am I missing?
Upvotes: 4
Views: 3834
Reputation: 11174
Case sensitive is the default. Dont put the insensitive flag in there.
Upvotes: 12