NSString* string=@"厂区名:养殖二厂;设发我发我备名:3号设备;are噶而过:温度;设备号:123456;";
NSString* pattern=@":|;";
NSRegularExpression *regex =[NSRegularExpression regularExpressionWithPattern:pattern options:0 error:nil];
NSArray *matches = [regex matchesInString:string options:0 range:NSMakeRange(0, string.length)];
NSMutableArray* rangeArr=[[NSMutableArray alloc] init];
for (NSTextCheckingResult* match in matches) {
[rangeArr addObject:[NSValue valueWithRange:match.range]];//找到每个分号和冒号的Range,存到数组
}
for (int i=0; i<rangArr.count;i=I+2){
NSRange range=[[rangeArr objectAtIndex:i] rangeValue];
NSInteger location=range.location;
NSRange nextRange=[[rangeArr objectAtIndex:i+1] rangeValue];
NSInteger nextLocation=nextRange.location;
NSRange finalRange=NSMakeRange(range.location+1, nextLocation-location-1);
NSString* finalStr=[string substringWithRange:finalRange];
NSLog(@"%@",finalStr);//这是解析到的字符串
}