let result = text.match(/(\d+)-(\d+)-(\d+)/) console.log(result); 1. 2. 3. 4. 输出结果 [ '2023-06-01', '2023', '06', '01', index: 0, input: '2023-06-01', groups: undefined ] 1. 2. 3. 4. 5. 6. 7. 8. 9. 方法一:使用命名捕获组 let text = "2023-06-0...
let re = new RegExp('(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})'); let match = re.exec('2021-12-14'); console.log(match); // 没有匹配到会返回null if(match){ let {year, month, day} = match.groups; console.log(year, month, day); // 2021 12 14 } 1....
let re = new RegExp('(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})'); let match = re.exec('2021-12-14'); console.log(match); // 没有匹配到会返回null if(match){ let {year, month, day} = match.groups; console.log(year, month, day); // 2021 12 14 } 1....
let re = new RegExp('(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})'); let match = re.exec('2021-12-14'); console.log(match); // 没有匹配到会返回null if(match){ let {year, month, day} = match.groups; console.log(year, month, day); // 2021 12 14 } 1....