swift
1let str = "<a href=\"http://hoge.com/\">ほげほげ</a>"
2let pattern = "<a href=\\\"(.+)\\\">(.+)<\\/a>"
3
4let regexp = try! NSRegularExpression(pattern: pattern, options: [])
5let range = NSRange(location: 0, length: str.characters.count)
6if let match = regexp.firstMatchInString(str, options: [], range: range) {
7 let href = (str as NSString).substringWithRange(match.rangeAtIndex(1))
8 let text = (str as NSString).substringWithRange(match.rangeAtIndex(2))
9 print("\"\(href)\" [\(text)]")
10 //=> "http://hoge.com/" [ほげほげ]
11} else {
12 print("not found")
13}
正規表現はあまり知らないのでゆるいです。
上記のコードでは無駄なスペースなどが入っているとNGです。
また、firstMatchInString()を使っているので、最初の一個だけです。