4

NSRegularExpression大文字と小文字を区別して検索するように指定する方法はありますか? 以下のテキストの大文字のタグ「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]]);

出力: (case-Insensative を使用すると、最初の「td」が期待どおりに取得されますが、本当に必要なのは「ACL」です

私はそれNSRegularExpressionCaseInsensitiveが間違っていることを知っていNSRegularExpressionCaseSensitiveます. ?(i)また、大文字と小文字を区別しない検索を指定するflagOptionもありますが、大文字と小文字を区別するものはありません。私は何が欠けていますか?

4

1 に答える 1

12

デフォルトでは大文字と小文字が区別されます。そこに insensitive フラグを置かないでください。

于 2012-02-08T17:07:58.377 に答える