gpt4 book ai didi

objective-c - NSRegularExpression 枚举匹配字符串 :options:range:usingBlock: giving a null result?

转载 作者:太空狗 更新时间:2023-10-30 03:50:09 26 4
gpt4 key购买 nike

我在解析器中使用了一个正则表达式,但是,它似乎给出了很多结果,这是我的代码:正则表达式:

self.seatSelectRegex = [NSRegularExpression regularExpressionWithPattern:@"Seat ([0-9]{1,2}): (.*) \\([$£€]?([0-9.]+) in chips\\).*$" options:NSRegularExpressionAnchorsMatchLines error:&error];

代码:

NSMutableDictionary *players = [[NSMutableDictionary alloc] init];
[self.seatSelectRegex enumerateMatchesInString:input options:NSMatchingCompleted range:NSMakeRange(0, input.length) usingBlock:
^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop)
{

NSLog(@"%lu", result.range.length);
Player *p = [[Player alloc] init];

p.name = [input substringWithRange:[result rangeAtIndex:2]];
p.seatNumber = [input substringWithRange:[result rangeAtIndex:1]].intValue;
p.stack = [input substringWithRange:[result rangeAtIndex:3]].doubleValue;

[players setValue:p forKey:p.name];
}];

我期望我的输入有 3 个结果,但是,我得到 4 个,其中最后一个结果的范围是 location = 0 和 length = 0(前三个都是正确的)。这是常见行为吗?我应该只检查范围的位置和长度,还是某处有错误?

对于它的值(value),这是我的输入:

PokerStars Hand #81669312371:  Hold'em No Limit ($0.01/$0.02 USD) - 2012/06/08 16:57:33 CET [2012/06/08 10:57:33 ET]
Table 'Icarus III' 6-max Seat #2 is the button
Seat 2: SanderDecler ($2 in chips)
Seat 3: ehrli87 ($0.90 in chips)
Seat 4: umar.11 ($1.60 in chips)
ehrli87: posts small blind $0.01
umar.11: posts big blind $0.02
*** HOLE CARDS ***
Dealt to SanderDecler [Kh 7d]
SanderDecler: raises $0.04 to $0.06
ehrli87: folds
umar.11: calls $0.04
*** FLOP *** [Jc Tc Jh]
umar.11: checks
SanderDecler: bets $0.08
umar.11: raises $0.24 to $0.32
SanderDecler: folds
Uncalled bet ($0.24) returned to umar.11
umar.11 collected $0.28 from pot
*** SUMMARY ***
Total pot $0.29 | Rake $0.01
Board [Jc Tc Jh]
Seat 2: SanderDecler (button) folded on the Flop
Seat 3: ehrli87 (small blind) folded before Flop
Seat 4: umar.11 (big blind) collected ($0.28)

最佳答案

这是因为您将 NSMatchingReportCompletion 选项与 enumerateMatchesInString:options:range:usingBlock: 一起使用。来自 Apples documentation :

If the NSMatchingReportCompletion matching option is specified, the Block object will be called once after matching is complete, with nil result and the NSMatchingCompleted matching flag is set in the flags passed to the Block, plus any additional relevant “NSMatchingFlags” from among NSMatchingHitEnd, NSMatchingRequiredEnd, or NSMatchingInternalError.

你将最后一个 block 调用视为位置和长度设置为 0 的范围的原因是因为你将消息发送到 nil 将返回 nil(这是整数 0)。

关于objective-c - NSRegularExpression 枚举匹配字符串 :options:range:usingBlock: giving a null result?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10961779/

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