Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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
Regex Can';无法创建NSRegularExpression,因为;不能';t创建(元类型)escape NSRegularExpression“;_Regex_Nsregularexpression - Fatal编程技术网

Regex Can';无法创建NSRegularExpression,因为;不能';t创建(元类型)escape NSRegularExpression“;

Regex Can';无法创建NSRegularExpression,因为;不能';t创建(元类型)escape NSRegularExpression“;,regex,nsregularexpression,Regex,Nsregularexpression,我正在尝试创建以下NSRegularExpression(我正在尝试查找所有逗号、、左括号(、右括号))和反斜杠\): 但它返回.None,并出现以下错误: Couldn't create (Metatype) escape NSRegularExpression 以及以下userInfo: NSInvalidValue: "[,\(\)\]" 这意味着什么?字符类中的反斜杠文字没有正确转义。它在字符串文本中使用了两个反斜杠,而不是四个 var error: NSError? NSRegul

我正在尝试创建以下
NSRegularExpression
(我正在尝试查找所有逗号
、左括号
、右括号
)和反斜杠
\
):

但它返回
.None
,并出现以下错误:

Couldn't create (Metatype) escape NSRegularExpression
以及以下
userInfo

NSInvalidValue: "[,\(\)\]"

这意味着什么?

字符类中的反斜杠文字没有正确转义。它在字符串文本中使用了两个反斜杠,而不是四个

var error: NSError?
NSRegularExpression(pattern: "[,\\(\\)\\]", options: nil, error: &error)
应该是:

var error: NSError?
NSRegularExpression(pattern: "[,\\(\\)\\\\]", options: nil, error: &error)
我认为
无法创建(元类型)转义
错误是指转义不完全的反斜杠导致转义最后的方括号,这使得字符类定义无效

var error: NSError?
NSRegularExpression(pattern: "[,\\(\\)\\\\]", options: nil, error: &error)