Created
August 17, 2017 10:39
-
-
Save julesjans/0ee09a8868c310fc18a7070bdae19120 to your computer and use it in GitHub Desktop.
Simplified regex handler in swift
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
import Foundation | |
extension String { | |
func regex(_ pattern: String) -> Bool { | |
return self.range(of: pattern, options: .regularExpression) != nil | |
} | |
} | |
let pattern = "http[s]?://[w]*.?booking.com.*aid=[0-9]+" | |
var str1 = "https://booking.com/hotel/gb/the-justin-james-ltd.html?aid=925669" | |
str1.regex(pattern) | |
var str2 = "https://www.booking.com/hotel/gb/the-justin-james-ltd.html?aid=925669" | |
str2.regex(pattern) | |
var str3 = "http://www.booking.com" | |
str3.regex(pattern) | |
var str4 = "http://booking.com" | |
str4.regex(pattern) | |
var str5 = "booking.com" | |
str5.regex(pattern) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment