EdwardZZZ / articles

工作点滴记录
2 stars 0 forks source link

正则支持命名了 #49

Open EdwardZZZ opened 5 years ago

EdwardZZZ commented 5 years ago
const REGEXP_DATE = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/;
const { groups: { year, month, day } } = REGEXP_DATE.exec('2018-12-12');
console.log(year, month, day);
EdwardZZZ commented 4 years ago
const str = 'HelloWorld';

console.log(str.replace(/(.)?([A-Z])/g, (str1, str2, str3) => {
    console.log(str1, str2, str3)
    if (str2) return `${str2}-${str3.toLowerCase()}`
    return str3.toLowerCase();
}));