Created
October 20, 2015 12:59
-
-
Save maximbilan/b4347b16ebe0e38c6410 to your computer and use it in GitHub Desktop.
YouTubeParseLinks.swift
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
let url = "https://www.youtube.com/watch?v=ZGNvt_L_cag" | |
do { | |
let regex = try NSRegularExpression(pattern: "(?<=v(=|/))([-a-zA-Z0-9_]+)|(?<=youtu.be/)([-a-zA-Z0-9_]+)", options: NSRegularExpressionOptions.CaseInsensitive) | |
let match = regex.firstMatchInString(url, options: NSMatchingOptions.ReportProgress, range: NSMakeRange(0, url.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))) | |
let range = match?.rangeAtIndex(0) | |
let youTubeID = (url as NSString).substringWithRange(range!) | |
print(youTubeID) | |
} catch { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment