Skip to content

Instantly share code, notes, and snippets.

@s-aska
Created October 30, 2014 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-aska/ad92c43b45b9024b896d to your computer and use it in GitHub Desktop.
Save s-aska/ad92c43b45b9024b896d to your computer and use it in GitHub Desktop.
import Foundation
import SwifteriOS
struct TwitterVia {
let name: String
let URL: NSURL?
struct Static {
static let regexp = NSRegularExpression(pattern: "<a href=\"(.+)\" rel=\"nofollow\">(.+)</a>", options: NSRegularExpressionOptions(0), error: nil)!
}
init(_ source: String) {
if let match = Static.regexp.firstMatchInString(source, options: NSMatchingOptions(0), range: NSMakeRange(0, countElements(source))) {
if match.numberOfRanges > 0 {
self.URL = NSURL(string: (source as NSString).substringWithRange(match.rangeAtIndex(1)) as String)
self.name = (source as NSString).substringWithRange(match.rangeAtIndex(2))
return
}
}
self.name = source
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment