给定这两个字符串:
let query = "select color, year from car where color = blue and year = 2002";
Run Code Online (Sandbox Code Playgroud)
或者
let query = "select color, year from car";
Run Code Online (Sandbox Code Playgroud)
我创建了以下内容RegExp来String.prototype.match提取列、表名和 where 子句(可选)
var results = query.match(/select (.*) from (.*) where (.*)/);
Run Code Online (Sandbox Code Playgroud)
对于第一个查询,结果是我所期望的:
[
'select color, year from car where color = blue and year = 2002',
'color, year',
'car',
'color = blue and year = 2002',
index: 0,
input: 'select color, year from car where color = blue and …Run Code Online (Sandbox Code Playgroud)