2016-07-08 75 views
1

我想从vimeo网址提取视频ID,任何机构都可以帮助我使用RegEx。从vimeo网址提取vimeo视频ID objective-c

视频地址的类型可以是

https://vimeo.com/173652088 

的这只是一个样本网址。 RegEx应该适用于所有的vimeo网址。

+0

是总是在结束的视频ID?或者什么可以是其他格式? – hariszaman

+0

是的视频ID总是在url.Ex-/videoId – Developer

+0

的末尾,那么为什么你尝试注册前,请尝试简单替换发生的字符串 –

回答

1

PLZ试试这个代码

NSString *yourStr = @"https://vimeo.com/173652088"; 
NSString *str = [yourStr stringByReplacingOccurrencesOfString: @"https://" withString:@""]; 

NSArray *arryVedios =[str componentsSeparatedByString:@"/"] ; 

NSString *id= [ arryVedios lastObject]; 
NSLog(@"id= %@",id); 

为每url.but您的ID此代码的工作必须在最后。

+0

不会工作的东西“https://vimeo.com/173031270?a=1&b=2” – hariszaman

1
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); 

enter image description here

+0

如果你的网址是动态的,然后去正则表达式 –

0

如果你确定这是一个VIMEO URL那么下面就在这里工作

[^\/]+(?=\/$|$) 

在线测试仪 online regex tester

您也可以从提取lastComponent网址

NSURL* url = [NSURL URLWithString:@"https://vimeo.com/173031270"]; 
NSLog(@video id: %@", url.lastPathComponent); 

注意,如果你有一个像网址该解决方案将失败“https://vimeo.com/173031270?a=1&b=2