网上找了下,可以利用正则表达式完成,结果是个数组,数组元素是NSTextCheckingResult。
效果不错,小记一下。
直接看示例代码
NSString *str = @"ddididd{{{didd}}diid"; NSString *regexStr = @"d[i]+d"; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexStr options:0 error:nil]; NSArray *matches = [regex matchesInString:str options:0 range:NSMakeRange(0,str.length)]; for (NSTextCheckingResult* match in matches) { NSRange range = match.range; NSString *temp = [str substringWithRange:range]; NSLog(@"RESULT===%@",temp); }
执行结果
2015-08-24 18:49:32.234 test02[16720:2141808] RESULT===did 2015-08-24 18:49:32.235 test02[16720:2141808] RESULT===did 2015-08-24 18:49:32.235 test02[16720:2141808] RESULT===diid原文链接:https://www.f2er.com/regex/360029.html