gpt4 book ai didi

ios - NSRegularExpression,指定区分大小写匹配?

转载 作者:可可西里 更新时间:2023-11-01 05:04:51 24 4
gpt4 key购买 nike

有没有办法使用 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]]);

输出:(在不区分大小写的情况下,我得到了预期的第一个“td”,而我真正想要的是“ACL”

我知道 NSRegularExpressionCaseInsensitive 是错误的,我希望有一个 NSRegularExpressionCaseSensitive。还有一个 flagOption ?(i) 也指定了不区分大小写的搜索,但同样没有指定区分大小写的搜索。我错过了什么?

最佳答案

默认区分大小写。不要把不敏感的标志放在那里。

关于ios - NSRegularExpression,指定区分大小写匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9198053/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com