【发布时间】:2016-03-03 01:28:29
【问题描述】:
我有一串 html 标签,我正在其中寻找特定模式 - 它应该是“后续”,后面可以跟空格、冒号字符或换行符,后面跟 8 到 13 位之间的数字。
我正在使用下面的正则表达式来找出这种模式
NSString *followUp = @" Follow-up 614233222 Follow-up 请在后续标签中包含以下行,其中 Follow-Up \n:123212323 567 Follow-Up 1234231234 需要忽略 123 请在此请求的后续电子邮件中包含以下行。";
NSString *pattern = [NSString stringWithFormat:@"Follow-up(\\s|:)*\\d{8,13}"];
NSRegularExpression *regExp = [NSRegularExpression regularExpressionWithPattern:pattern
options:NSRegularExpressionCaseInsensitive
error:NULL];
[regExp enumerateMatchesInString:followUp
options:0
range:NSMakeRange(0, followUp.length)
usingBlock:^(NSTextCheckingResult * _Nullable result, NSMatchingFlags flags, BOOL * _Nonnull stop) {
NSString * foundMatch = [followUp substringWithRange:[result rangeAtIndex:0]];
NSLog(@"found is %@",foundMatch);
}];
它给出了结果,但有时它没有给出所有匹配的结果。 有人可以帮助我在这里做错了什么。
【问题讨论】:
标签: ios objective-c regex nsregularexpression