?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);//這是解析到的字符串
? ? }