您的位置:首页 > 移动开发 > Objective-C

objective-c 正则表达式 -NSRegularExpression 提取匹配内容

2016-09-12 09:48 841 查看
NSString * str = @"http://yourhostaa/index.php?path=hellow/index&id=893&cid=123;http://yourhostbb/index.php?path=hellow/index&id=888&cid=456";
NSString * patton = @"http://([^/]+)/index.php\\?path=hellow/index&id=(\\d+)&cid=(\\d+)";

NSArray *array =    nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:patton options:NSRegularExpressionCaseInsensitive error:nil];
array = [regex matchesInString:str options:0 range:NSMakeRange(0, [str length])];

NSString *str1 = nil;
for (NSTextCheckingResult* b in array)
{
for(int i=0;i<b.numberOfRanges;i++){
str1 = [str substringWithRange:[b rangeAtIndex:i]];
NSLog(@"str -> %@",str1);
}

}
使用NSRegularExpression 提取匹配内容。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: