All I need is to check using NSPredicate and evaluate pattern if my string contains .page.link phrase.
extension String {
func isValid(for string: String) -> Bool {
NSPredicate(format: "SELF MATCHES %@", string).evaluate(with: self)
}
}
let pattern = ".page.link" // "\\.page\\.link"
"joyone.page.link/abcd?title=abcd".isValid(for: pattern) //false
"joyone.page.link".isValid(for: pattern) //false
"joyone.nopage.link/abcd?title=abcd".isValid(for: pattern) //false
I know there is a simpler way to do this, but it is a part of something bigger, and my pattern is just case in enum.
First two should be true.
MATCHESconsiders always the whole string.range(of:options:)can also talkRegexand is easier to use