[英]Regular Expression,Find pattern of String ,Number and white\newline spaces
我有一個html標簽字符串,我正在其中尋找一個特定的模式-應該為“跟進”,其后可以跟空格,冒號或換行符,后跟8到13位之間的數字。
我在下面的正則表達式中使用以找出此模式
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);
}];
它給出結果,但是一段時間沒有給出所有匹配的結果。 有人可以幫我在這里做錯什么嗎。
嘗試這個
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.