0
.plistファイルに格納された正規表現を取得してNSPredicateに供給すると、エラーが発生します。プログラミングの基本概念は何ですか?.plistファイルのRegex文字列を使用しているときにこのエラーが発生するのはなぜですか?
以前私は、次の
static let PASSWORD_REGEX: String = "^[a-zA-Z_0-9\\-#[email protected]~`%&*()_+=|\"\':;?/>.<,]{6,15}$"
そして、このようなパターンマッチのためにそれを供給ように正規表現を使用していました。それはうまくいきました。
私が変更したものは、この正規表現の文字列を.plistファイルに移動して、そこから取得しています。 : - 私のplistの中
static let PASSWORD_REGEX: String = Constants.getCustomizableParameter(forKey: "PASSWORD_REGEX")
static func getCustomizableParameter(forKey: String) -> String {
var customizableParameters: NSDictionary?
if let customizableParametersPlistPath = Bundle.main.path(forResource: "CustomizableParameters", ofType: "plist") {
customizableParameters = NSDictionary(contentsOfFile: customizableParametersPlistPath)
}
if customizableParameters != nil {
return customizableParameters![forKey] as! String
} else {
return ""
}
}
今私は、同じパスワード検証機能を使用していたとき。あなたは文字(例えば\"
代わりに、単純な"
の)をエスケープする必要がコード内の文字列リテラルで
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Can't do regex matching, reason: Can't open pattern U_REGEX_INVALID_RANGE (string asdasd, pattern ^[a-zA-Z_0-9\\-#[email protected]~`%&*()_+=|\"\':;?/>.<,]{6,15}$, case 0, canon 0)'