Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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
如果字符串包含算术运算符,则mongodb中的正则表达式错误_Mongodb_Meteor_Mongodb Query_Meteorite_Minimongo - Fatal编程技术网

如果字符串包含算术运算符,则mongodb中的正则表达式错误

如果字符串包含算术运算符,则mongodb中的正则表达式错误,mongodb,meteor,mongodb-query,meteorite,minimongo,Mongodb,Meteor,Mongodb Query,Meteorite,Minimongo,在meteor应用程序中使用Mongodb,我正在使用正则表达式进行查询,以检查数据库中是否已经存在名称或代码。在我的字符串中包括所有数字和特殊字符。但当正则表达式在字符串中找到一个特殊字符++时,它给出了错误 Exception while invoking method 'createSubject' SyntaxError: Invalid regular expression: /^C++$/: Nothing to repeat I20140109-13:15:21.277(5.5)

在meteor应用程序中使用Mongodb,我正在使用正则表达式进行查询,以检查数据库中是否已经存在名称或代码。在我的字符串中包括所有数字和特殊字符。但当正则表达式在字符串中找到一个特殊字符
++
时,它给出了错误

Exception while invoking method
'createSubject' SyntaxError: Invalid regular expression: /^C++$/: Nothing to repeat
I20140109-13:15:21.277(5.5)?在新的RegExp()中

我的代码是

var code_regex = new RegExp(["^",code,"$"].join(""),"i");
var curr = Meteor.curri.findOne({code: code_regex});

它使用字符串,但我尝试了代码> C++<代码>,并产生了上述错误。

你需要逃离你的字符,因为C++是正则表达式的一部分,用< C++ >代码>寻找更多的前表达式的匹配。 发件人:

RegExp.escape = function(text) {
   return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
};

var code_regex = new RegExp(["^",
                             RegExp.escape(code),
                             "$"].join(""),"i");