错误域 = NSCocoaErrorDomain 代码 = 2048 NSInvalidValue 与字符串正则表达式
Posted
技术标签:
【中文标题】错误域 = NSCocoaErrorDomain 代码 = 2048 NSInvalidValue 与字符串正则表达式【英文标题】:Error Domain=NSCocoaErrorDomain Code=2048 NSInvalidValue with string regex 【发布时间】:2019-11-06 03:01:30 【问题描述】:我有以下游乐场:
let regexStringElo = "^(?:506721|506728|506729|506730|506733|506745|506746|506747|506753|506775|506776|509067|509068|509069|509098|509100|509107|509109|650487|650496|650497|650499|650500|650501|650578|650586|650906|650907|650908|650909|650910|650911|650922|650938|650946|650948|651653|651657|651665|651676|651678|655001|655003|655015|650503|650504|650506|650510|650511|650513|650518|650519|650520|650521|650522|650523|650524|650582|650723|655013|655056|655057|506722|506724|506741|506742|509042|509045|509048|627780|650507|650508|650512|650920|650921|651658|651659|651677|655007|655008|504175|506718|506720|506725|506726|506727|506731|506732|506734|506735|506736|506739|506743|506774|506778|509000|509001|509003|509007|509020|509021|509022|509023|509035|509039|509040|509041|509051|509052|509053|509064|509065|509066|509073|509074|509077|509078|509079|509080|509091|509092|509093|509094|509104|509108|636368|650031|650033|650036|650037|650038|650039|650040|650041|650042|650043|650044|650045|650047|650407|650408|650485|650486|650488|650489|650490|650491|650492|650493|650494|650495|650502|650509|650514|650515|650525|650526|650527|650528|650529|650530|650577|650580|650583|650584|650585|650721|650722|650726|650727|650901|650902|650903|650904|650905|650912|650913|650914|650915|650916|650917|650918|650919|650928|650939|650947|650954|650955|650971|651652|651654|651655|651656|651660|651661|651663|651664|651675|655000|655002|655004|655006|655009|655010|655014|655051|650724|655052|650587|650725|650409|650588|650589|509070|509071|650406|506750|650439|650516|650517|651662|655012|506707|506708|506715|506719|509054|509055|509056|509057|509058|509059|509060|509061|509062|509063|509084|509106|650498|650579|655005)\\d,10$"
func matchCardWithRegex(number:String,regex:String) -> Bool
let rx = try! NSRegularExpression(pattern: regex)
let range = NSRange(location: 0, length: number.utf16.count)
return rx.firstMatch(in: number, options: [], range: range) != nil
matchCardWithRegex(number: "6362970000457013", regex: regexStringElo)
但我得到错误 NSInvalidValue 与字符串正则表达式。怎么了?
【问题讨论】:
【参考方案1】:这是,10
中的逗号 - 不是有效的运算符:https://developer.apple.com/documentation/foundation/nsregularexpression
如果您去掉逗号或将逗号移到 10 之后,它将运行(尽管两者都不会返回任何匹配项)
【讨论】:
以上是关于错误域 = NSCocoaErrorDomain 代码 = 2048 NSInvalidValue 与字符串正则表达式的主要内容,如果未能解决你的问题,请参考以下文章
Json 错误:错误域 = NSCocoaErrorDomain 代码 = 3840“无值”。 UserInfo=NSDebugDescription=无值。
错误域 = NSCocoaErrorDomain 代码 = 3840 “字符周围的值无效
iOS swift 中的错误域 = NSCocoaErrorDomain 代码 = 3840?
iOS:- 错误:无法创建存储目录。错误域 = NSCocoaErrorDomain 代码 = 512
如何修复“错误域 = NSCocoaErrorDomain 代码 = 3840”无价值。“UserInfo = NSDebugDescription = 无价值。”