我想从一个vimeo中提取视频id,任何一个人都可以帮我做同样的RegEx。
视频url可以是类型的
https://vimeo.com/173652088这只是一个样本url。RegEx应该适用于所有的vimeo。
发布于 2016-07-08 10:33:30
请试试这段代码
NSString *yourStr = @"https://vimeo.com/173652088";
NSString *str = [yourStr stringByReplacingOccurrencesOfString: @"https://" withString:@""];
NSArray *arryVedios =[str componentsSeparatedByString:@"/"] ;
NSString *id= [ arryVedios lastObject];
NSLog(@"id= %@",id);此代码适用于您的id必须位于最后的每个url.but。
发布于 2016-07-08 10:06:19
NSString *old = @"https://vimeo.com/173652088";
NSString *new = [old stringByReplacingOccurrencesOfString: @"https://vimeo.com/" withString:@""];
NSLog(@"new= %@", new);
NSString *newone = [[old componentsSeparatedByString:@"/"] lastObject];
NSLog(@"newone= %@", newone);

发布于 2016-07-08 10:30:59
如果您确定这是一个vimeo url,那么下面的内容就可以了。
[^\/]+(?=\/$|$)在线测试器在这里在线判读仪
还可以从Url中提取lastComponent。
NSURL* url = [NSURL URLWithString:@"https://vimeo.com/173031270"];
NSLog(@video id: %@", url.lastPathComponent);请注意,如果您有像"https://vimeo.com/173031270?a=1&b=2“这样的url,则此解决方案将失败。
https://stackoverflow.com/questions/38263306
复制相似问题