Last active
October 20, 2015 13:02
-
-
Save maximbilan/dfa64aea75206af2bba6 to your computer and use it in GitHub Desktop.
YouTubeParseLinks.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *url = @"https://www.youtube.com/watch?v=ZGNvt_L_cag"; | |
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(?<=v(=|/))([-a-zA-Z0-9_]+)|(?<=youtu.be/)([-a-zA-Z0-9_]+)" options:NSRegularExpressionCaseInsensitive error:nil]; | |
NSTextCheckingResult *match = [regex firstMatchInString:url options:0 range:NSMakeRange(0, [url length])]; | |
NSRange range = [match rangeAtIndex:0]; | |
NSString *youTubeID = [url substringWithRange:range]; | |
NSLog(@"%@", youTubeID); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment