示例:js使用正则表达式group来提取字符串中的数据

var linkStr = "/black-mountain/35-cotton-creek-cir-black-mountain-nc-421_537763.html";
// 括号表示组。访问可以用group[index]来访问每组的信息
var linkRegx = /\/([^\/]+)\/.+-(\d+)_(\d+).html/;
var group = linkStr.match(linkRegx);
console.log(group);



/*
输出结果为:
[ '/black-mountain/35-cotton-creek-cir-black-mountain-nc-421_537763.html',
  'black-mountain',
  '421',
  '537763',
  index: 0,
  input: '/black-mountain/35-cotton-creek-cir-black-mountain-nc-421_537763.html' ]
*/

你可能感兴趣的:(示例:js使用正则表达式group来提取字符串中的数据)