Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.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
Javascript 解析node.js中的WHERE子句_Javascript_Node.js_Regex - Fatal编程技术网

Javascript 解析node.js中的WHERE子句

Javascript 解析node.js中的WHERE子句,javascript,node.js,regex,Javascript,Node.js,Regex,我试图将mysql查询的WHERE子句解析为一个表达式,以从json文件中获取数据 例如: `price`=8.95 AND `title`="The Lord price= AND of the Rings" 在替换左侧的价格和标题值后,应将上面的示例转换为下面的字符串 8.95==8.95 && 'The Lord price= AND of the Rings'=="The Lord price= AND of the Rings" 我已经创建了一个代码()来实现这一点

我试图将mysql查询的WHERE子句解析为一个表达式,以从json文件中获取数据

例如:

`price`=8.95 AND `title`="The Lord price= AND of the Rings"
在替换左侧的价格和标题值后,应将上面的示例转换为下面的字符串

8.95==8.95 && 'The Lord price= AND of the Rings'=="The Lord price= AND of the Rings"
我已经创建了一个代码()来实现这一点,但如果我在值中添加和`如下所示(如果条件不匹配,则返回false),则该代码将中断


所以我想知道还有其他更好的方法来实现这一点吗?

在第一步中,使用

并存储所有
组1
匹配项


在第二步中,对每个匹配项进行替换,最后将所有匹配项与字符串
合并。在第一步中,使用

并存储所有
组1
匹配项


在第二步中,对每个匹配项进行替换,最后使用字符串
稍微不同的方法合并所有匹配项,而不考虑引用字符串的形式;按引号外的
拆分,替换并合并:

let source='price`=8.95,'title`='The Lord price=AND of The Rings';
让结果=源
.split(/\s*\bAND\b\s*(?![^`“]+”)/)
.map(s=>s.replace(/`\w+`=(.*)/,'$1==$1'))
.加入(“&&”);
控制台日志(结果)

.as控制台包装{max height:100%!important;top:0;}
方法稍有不同,与引用字符串的形式无关;按引号外的
拆分,替换并合并:

let source='price`=8.95,'title`='The Lord price=AND of The Rings';
让结果=源
.split(/\s*\bAND\b\s*(?![^`“]+”)/)
.map(s=>s.replace(/`\w+`=(.*)/,'$1==$1'))
.加入(“&&”);
控制台日志(结果)
。作为控制台包装{最大高度:100%!重要;顶部:0;}
var obj = {price: 8.95, title: "'The Lord price= AND `of the Rings'"};
var whereString = '`price`=8.95 AND `title`="The Lord price= AND `of the Rings"';
/(`[^`]+`=(?:"[^"]+"|\S+))(?:\s+AND\s+|$)/g