[英]Regular Expression,Find pattern of String ,Number and white\newline spaces
I have string of html tags in which I am looking for a particular pattern- It should be "Follow-up" which can be followed by space ,colon character or new lines ,followed by number between 8 and 13 digit. 我有一个html标签字符串,我正在其中寻找一个特定的模式-应该为“跟进”,其后可以跟空格,冒号或换行符,后跟8到13位之间的数字。
I am using below Regular Expression to find out this pattern 我在下面的正则表达式中使用以找出此模式
NSString *followUp = @" Follow-up 614233222 Follow-up Please inlcude the below line in follow up tags where Follow-Up \\n:123212323 567 Follow-Up 1234231234 which needs to be ignore with 123 <\\n>Please include the line below in follow-up emails for this request.<\\n><\\n>"; NSString * followUp = @“跟进614233222跟进请在跟进标记中包含以下行,其中跟进\\ n:123212323 567跟进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);
}];
It is giving result but some time it is not giving all matching results. 它给出结果,但是一段时间没有给出所有匹配的结果。 Can someone please help me what I am doing wrong here. 有人可以帮我在这里做错什么吗。
Try this 尝试这个
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: NSLog的:
found is 614233222
found is 123212323
found is 1234231234
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.