Created
November 24, 2020 01:08
-
-
Save bright23/864f94edfd6c7518658fc32eb03bc150 to your computer and use it in GitHub Desktop.
url_and_text
This file contains hidden or 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 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