Created
August 27, 2012 22:11
-
-
Save davecowart/3492791 to your computer and use it in GitHub Desktop.
Obj-c YouTube Regex
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
NSError *error = nil; | |
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(?<=(?:v|i)=)[a-zA-Z0-9-]+(?=&)|(?<=(?:v|i)\\/)[^&\n]+|(?<=embed\\/)[^\"&\n]+|(?<=(?:v|i)=)[^&\n]+|(?<=youtu.be\\/)[^&\n]+" options:NSRegularExpressionCaseInsensitive error:&error]; | |
NSString *link = [post objectForKey:@"link"]; | |
NSTextCheckingResult *match = [regex firstMatchInString:link options:0 range:NSMakeRange(0, [link length])]; | |
NSString *identifier = [link substringWithRange:match.range]; | |
NSString *html = [self embedYouTube:identifier frame:webView.frame]; | |
[webView loadHTMLString:html baseURL:nil]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment