I am a little new to using regex. I am getting the following error:
The operation couldn’t be completed. (Cocoa error 2048.)
when trying to build the following regular expression with NSRegularExpression in Swift:
let regex = try NSRegularExpression(pattern: "^(?=.*[A-Z])(?=.*[a-z]).{7-15}$", options: .CaseInsensitive)
I am trying to validate the user input string to contain at least one upper case letter and at least one lower case letter while restricting the length of the string to between 7 and 15 characters. Thanks
{7-15}
to{7,15}
, 2) Remove the.CaseInsensitive
flag, replace with[]
. (if the[]
is not accepted, trynil
instead). – Wiktor Stribiżew