检索文字里的手机号
程序员文章站
2022-03-09 20:03:27
...
- (NSArray *) getPhoneNumbersFromString:(NSString *)str {
NSError* error = nil;
NSString* regulaStr = @"(([0-9]{11})|((400|800)([0-9\\-]{7,10})|(([0-9]{4}|[0-9]{3})(-| )?)?([0-9]{7,8})((-| |转)*([0-9]{1,4}))?))";
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regulaStr
options:NSRegularExpressionCaseInsensitive
error:&error];
NSArray *arrayOfAllMatches = [regex matchesInString:str options:0 range:NSMakeRange(0, [str length])];
NSMutableArray *numbers = [NSMutableArray arrayWithCapacity:arrayOfAllMatches.count];
for (NSTextCheckingResult *match in arrayOfAllMatches) {
NSString *substringForMatch = [str substringWithRange:match.range];
[numbers addObject:substringForMatch];
}
return numbers;
}
上一篇: OC----类加载
下一篇: win10如何配置php环境变量