Skip to content

Instantly share code, notes, and snippets.

@bright23
Created November 24, 2020 01:08
Show Gist options
  • Save bright23/864f94edfd6c7518658fc32eb03bc150 to your computer and use it in GitHub Desktop.
Save bright23/864f94edfd6c7518658fc32eb03bc150 to your computer and use it in GitHub Desktop.
url_and_text
let a = "http://www.megasoft.co.jp"
let b = "https://shop.megasoft.co.jp/shop/"
let c = "http://www.google.co.jp/search?hl=ja&q=%U&lr="
let d = "amazon http://www.google.co.jp/search?hl=ja&q=%U&lr="
let e = "めちゃいい机 http://www.google.co.jp/search?hl=ja&q=%U&lr= #やすいよ #よいもんだよ"
let g = "めちゃいい机 http://www.google.co.jp/search?hl=ja&q=%U&lr= #やすいよ #よいもんだよ http://www.google.co.jp/search?hl=ja&q=%U&lr="
let u = "めちゃいい机 "
extension String {
func divideBySpace() -> [String] {
let a = self.replacingOccurrences(of: " ", with: " ")
let b = a.replacingOccurrences(of: "\n", with: " ")
return b.components(separatedBy: " ")
}
func containsHttp() -> Bool {
let pattern = "https?"
guard let regex = try? NSRegularExpression(pattern: pattern) else { return false }
let matches = regex.matches(in: self, range: NSRange(location: 0, length: self.count))
return matches.count > 0
}
}
a.containsHttp()
b.containsHttp()
c.containsHttp()
d.containsHttp()
e.containsHttp()
u.containsHttp()
let f = g.divideBySpace()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment