小编Joh*_*son的帖子

JavaScript RegExp 可选捕获组

给定这两个字符串:

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)

我创建了以下内容RegExpString.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)

javascript regex

6
推荐指数
1
解决办法
5794
查看次数

标签 统计

javascript ×1

regex ×1