I am trying to see if a specific string matches a regex pattern in swift. The code I have so far seems to check if any substring within the given string matches the regex.
let string = " (5"
let pattern = "[0-9]"
if string.rangeOfString(pattern, options: .RegularExpressionSearch) != nil {
print("matched")
}
The above code returns a match, even though the string as a whole does not match the pattern.
How i would like the code to operate:
" (5" -> no match
"(5" -> no match
"5" -> match
How the code currenty operated:
" (5" -> match
"(5" -> match
"5" -> match