Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 正则表达式从graph API URL获取Facebook用户ID?_Objective C_Ios_Regex_Facebook - Fatal编程技术网

Objective c 正则表达式从graph API URL获取Facebook用户ID?

Objective c 正则表达式从graph API URL获取Facebook用户ID?,objective-c,ios,regex,facebook,Objective C,Ios,Regex,Facebook,从以下格式的URL中提取用户ID的正则表达式是什么?例如,在下面的示例中,我希望在应用正则表达式后获得“1227627”作为匹配项 https://graph.facebook.com/1227627/movies?access_token=[access\u token]&限制=5000&偏移量=5000&\u后id=103108306395658 注意:我将在iOS/objective c中使用此选项 作为一些背景——我正在使用graphi API批处理请求。批处理请求最多可以包含20个单独

从以下格式的URL中提取用户ID的正则表达式是什么?例如,在下面的示例中,我希望在应用正则表达式后获得“1227627”作为匹配项

https://graph.facebook.com/1227627/movies?access_token=[access\u token]&限制=5000&偏移量=5000&\u后id=103108306395658

注意:我将在iOS/objective c中使用此选项


作为一些背景——我正在使用graphi API批处理请求。批处理请求最多可以包含20个单独的请求,不幸的是,单独的响应不会返回请求URL。我可以跟踪所有单独的请求,但是用这种方法解析出请求对应的用户ID会更简单

您可以使用“https?://graph.facebook.com/([0-9]+)/”,该号码将是第一个捕获组

大致如下:

// input URL
NSString *urlString = @"https://graph.facebook.com/1227627/movies?access_token=access_token]&limit=5000&offset=5000&__after_id=103108306395658";

// construct the regex
NSRegularExpression *regex = [NSRegularExpression 
      regularExpressionWithPattern:@"https?://graph\\.facebook\\.com/([0-9]+)/"  
                           options:NSRegularExpressionSearch 
                             error:nil];
// match against url
NSArray *matches = [regex matchesInString:urlString
                                  options:0
                                    range:NSMakeRange(0, [urlString length])];
// extract capturing group 1
for (NSTextCheckingResult *match in matches) {
    NSRange matchRange = [match rangeAtIndex:1];
    NSString *matchString = [urlString substringWithRange:matchRange];
    NSLog(@"%@", matchString);
}

太棒了,谢谢你这么完整的回答——你有学习正则表达式的方法吗?