- NSString *text = @"张三:010-88669900,李四232电话010-55443322发送0731-8373834垃圾费";
- //1.定义正则表达式
- NSString *regex = @"\\d{3,4}-\\d{7,8}";
- //2.创建正则表达式实现对象
- NSRegularExpression *expression = [[NSRegularExpression alloc] initWithPattern:regex options:NSRegularExpressionCaseInsensitive error:nil];
- //3. expression 查找符合正则表达式的字符串
- NSArray *items = [expression matchesInString:text options:NSMatchingReportProgress range:NSMakeRange(0, text.length)];
- //4.循环遍历查找出来的结果
- for (NSTextCheckingResult *result in items) {
- //符合表达的字符串的范围
- NSRange range = [result range];
- NSString *matchString = [text substringWithRange:range];
- NSLog(@"%@",matchString);
- }
推荐学习网站:http://www.jb51.net/tools/zhengze.html