Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios NSRegularExpression计算不正确_Ios_Swift - Fatal编程技术网

Ios NSRegularExpression计算不正确

Ios NSRegularExpression计算不正确,ios,swift,Ios,Swift,我有以下密码正则表达式,它在密码的在线regex测试仪上正确计算。123: /(?!^[0-9]*$)(?!^[a-z]*$)(?!^[A-Z]*$)(?!^[\\W]*$)(^[a-zA-Z0-9\\W]).{7,}/ let password = "Password.123" let regex = try! NSRegularExpression(pattern: "/(?!^[0-9]*$)(?!^[a-z]*$)(?!^[A-Z]*$)(?!^[\\W]*$)(^[a-zA-Z0-

我有以下密码正则表达式,它在密码的在线regex测试仪上正确计算。123:

/(?!^[0-9]*$)(?!^[a-z]*$)(?!^[A-Z]*$)(?!^[\\W]*$)(^[a-zA-Z0-9\\W]).{7,}/
let password = "Password.123"

let regex = try! NSRegularExpression(pattern: "/(?!^[0-9]*$)(?!^[a-z]*$)(?!^[A-Z]*$)(?!^[\\W]*$)(^[a-zA-Z0-9\\W]).{7,}/", options: [])

let range = NSRange(location: 0, length: password.count)
print("Valid: \(regex.firstMatch(in: password, options: [], range: range) != nil)")
在swift中执行NSRegularExpression时,它的计算结果不正确,无法找到密码的匹配项。123:

/(?!^[0-9]*$)(?!^[a-z]*$)(?!^[A-Z]*$)(?!^[\\W]*$)(^[a-zA-Z0-9\\W]).{7,}/
let password = "Password.123"

let regex = try! NSRegularExpression(pattern: "/(?!^[0-9]*$)(?!^[a-z]*$)(?!^[A-Z]*$)(?!^[\\W]*$)(^[a-zA-Z0-9\\W]).{7,}/", options: [])

let range = NSRange(location: 0, length: password.count)
print("Valid: \(regex.firstMatch(in: password, options: [], range: range) != nil)")

这是假的,但应该是真的。我哪里出错了?

从字符串中删除
/
。即

let regex = try! NSRegularExpression(pattern: "(?!^[0-9]*$)(?!^[a-z]*$)(?!^[A-Z]*$)(?!^[\\W]*$)(^[a-zA-Z0-‌​9\\W]).{7,}", options: [])

您是否尝试过从字符串中删除
/
?也就是说,
让regex=try!NSRegularExpression(模式:(?!^[0-9]*$)(?!^[a-z]*$)(?!^[a-z]*$)(?!^[a-zA-Z0-9\\W]*$)(^[a-zA-Z0-9\\W])。{7,}选项:[)
啊,谢谢,我会把它作为答案,以便您可以标记它。