Two character sequence \
-
is not a valid escape sequence in Swift String. When you need to pass \
-
to NSRegularExpression
as pattern, you need to write \\-
in Swift String literal.
So, your line should be something like this:
static let Regex_studio_tel = "^(0[0-9]{2,3}\\-)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?$"
ADDITION
As Rob commented, minus sign is not a special character in regex when appearing outside of [
]
, so you can write it as:
static let Regex_studio_tel = "^(0[0-9]{2,3}-)?([2-9][0-9]{6,7})+(-[0-9]{1,4})?$"