//name: url中的參數(shù)名稱
-(NSString*)getParamByName:(NSString*)name URLString:(NSString*)url{NSError*error;NSString*regTags=[[NSString alloc]initWithFormat:@"(^|&|\\?)+%@=+([^&]*)(&|$)",name];NSRegularExpression*regex=[NSRegularExpression regularExpressionWithPattern:regTags options:NSRegularExpressionCaseInsensitive error:&error];// 執(zhí)行匹配的過程N(yùn)SArray*matches=[regex matchesInString:url options:0range:NSMakeRange(0,[url length])];for(NSTextCheckingResult*matchinmatches){NSString*tagValue=[url substringWithRange:[match rangeAtIndex:2]];// 分組2所對應(yīng)的串returntagValue;}return@"";}
NSString *goodId = [self getParamByName:@"id" URLString:url];
goodId 取出來就是123456.