截取字符串里面的所有数字
NSString *string = @"123hello555165asdhasod0uqeqvdfdssxde23你好TG¥……&888imu67";
//正则表达式
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\d+" options:(NSRegularExpressionCaseInsensitive) error:nil];
//d+是正则表达式的表示方法
//寻找匹配的字符串存入数组
NSArray *arr = [regex matchesInString:string options:NSMatchingReportProgress range:NSMakeRange(0, string.length)];
NSString *numberStr = @"";
NSString *subString ;
NSMutableArray *tempArray = [NSMutableArray array]; ;
//数组遍历
for(NSTextCheckingResult *result in arr) {
subString = [string substringWithRange:result.range];
//把遍历之后的结果放在可变数组里
[tempArray addObject:subString];
}
//所有元素用-分开
numberStr = [tempArray componentsJoinedByString:@"-"];
NSLog(@"====数字截取====%@",numberStr);