Kro*_*owy 3 regex macos cocoa objective-c
我很高兴Lion介绍NSRegularExpression,但我无法理解为什么模式.*匹配像"a"这样的字符串中的两次出现(文本可以更长).
我使用以下代码:
NSError *anError = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@".*"
options:0
error:&anError];
NSString *text = @"a";
NSUInteger counter = [regex numberOfMatchesInString:text
options:0
range:NSMakeRange(0, [text length])];
NSLog([NSString stringWithFormat:@"counter = %u", counter]);
Run Code Online (Sandbox Code Playgroud)
控制台的输出是:
2011-07-27 22:03:27.689 Regex [1930:707] counter = 2
谁能解释为什么会这样?