Skip to content

Instantly share code, notes, and snippets.

@tonkotsuboy
Created July 3, 2020 05:47
Show Gist options
  • Save tonkotsuboy/82c354c9ad9ad58ed51204391f48c92a to your computer and use it in GitHub Desktop.
Save tonkotsuboy/82c354c9ad9ad58ed51204391f48c92a to your computer and use it in GitHub Desktop.
名前つきキャプチャー
const regrex = /よく(?<food>.*)食う(?<animal>.*)だ/u;
const result1 = "隣の客はよく柿食う客だ".match(regrex);
console.log(result1.groups.food);
console.log(result1.groups.animal);
const result2 = "隣の客はよく牡蠣食う吉田拓郎だ".match(regrex);
console.log(result2.groups.food);
console.log(result2.groups.animal);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment