更新时间:2023-11-27 08:41:04
使用捕获组:
var res1 = '/this/12/that/34'.match(/\/this\/([0-9a-zA-Z]+)\/that\/([0-9a-zA-Z]+)/);
你会得到一个包含 3 个元素的数组:
You will get an array containing 3 elements:
整场比赛;
The whole match;
12
34
并且您可以使用 .slice(1)
删除第一个元素:
And you can use .slice(1)
to remove the first element:
var res1 = '/this/12/that/34'.match(/\/this\/([0-9a-zA-Z]+)\/that\/([0-9a-zA-Z]+)/).slice(1);