我正在尝试将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"
我已经创建了一个代码(jsfiddle)来实现这一点,但是如果我在值中添加AND`,则如下所示(如果条件不匹配,它将返回false),这会中断。
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"';
所以我想了解是否还有其他更好的方法来实现这一目标?
[我正在尝试将mysql查询的WHERE子句解析为一个表达式,以从json文件获取数据,例如:上面的示例应该是`price` = 8.95 AND`title` =“ The Lord price = AND of the Rings”。 ..
第一步中,将whereString
与regex pattern分开