正则表达式,查找字符串、数字和 white\newline 空格的模式
Regular Expression,Find pattern of String ,Number and white\newline spaces
我有一串 html 标签,我在其中寻找一个特定的模式——它应该是 "Follow-up",后面可以跟 space、冒号字符或换行符,后跟 8 到 13 位数字。
我正在使用下面的正则表达式来找出这个模式
NSString *followUp = @" Follow-up 614233222 Follow-up 请在 follow-up 标签中包含以下行,其中 Follow-Up \n:123212323 567 Follow-Up 1234231234 需要用 123 <\n 忽略>请在此请求的后续电子邮件中包含以下行。<\n><\n>";
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);
}];
它正在给出结果,但有时它并没有给出所有匹配的结果。
有人可以帮我看看我做错了什么吗?
试试这个
Follow-up[\s\n\n:]+[\d]{8,13}
NSString *pattern = [NSString stringWithFormat:@"Follow-up[\s\n\\n:]+([\d]{8,13})"];
NSRegularExpression *regExp = [NSRegularExpression regularExpressionWithPattern:pattern options:NSRegularExpressionCaseInsensitive error:nil];
[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:1]];
NSLog(@"found is %@",foundMatch);
NSLog:
found is 614233222
found is 123212323
found is 1234231234
我有一串 html 标签,我在其中寻找一个特定的模式——它应该是 "Follow-up",后面可以跟 space、冒号字符或换行符,后跟 8 到 13 位数字。
我正在使用下面的正则表达式来找出这个模式
NSString *followUp = @" Follow-up 614233222 Follow-up 请在 follow-up 标签中包含以下行,其中 Follow-Up \n:123212323 567 Follow-Up 1234231234 需要用 123 <\n 忽略>请在此请求的后续电子邮件中包含以下行。<\n><\n>";
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);
}];
它正在给出结果,但有时它并没有给出所有匹配的结果。 有人可以帮我看看我做错了什么吗?
试试这个
Follow-up[\s\n\n:]+[\d]{8,13}
NSString *pattern = [NSString stringWithFormat:@"Follow-up[\s\n\\n:]+([\d]{8,13})"];
NSRegularExpression *regExp = [NSRegularExpression regularExpressionWithPattern:pattern options:NSRegularExpressionCaseInsensitive error:nil];
[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:1]];
NSLog(@"found is %@",foundMatch);
NSLog:
found is 614233222
found is 123212323
found is 1234231234