Skip to content

Instantly share code, notes, and snippets.

@caub
Created April 6, 2018 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caub/7284d41ff8bc9bc607514923b3ab9b24 to your computer and use it in GitHub Desktop.
Save caub/7284d41ff8bc9bc607514923b3ab9b24 to your computer and use it in GitHub Desktop.
// ## like \1 but named:
/(?<fruit>apple|fig)==\k<fruit>/u.test('fig==fig')
// true
// ## named group captures:
'we can'.replace(/(?<subject>\w+) (?<verb>\w+)/u, '$<subject>...$<verb>')
//"we...can"
'yes, we can'.replace(/(?<w>\w+)[,\s]+/gu, '$<w>...')
// "yes...we...can"
'2018-03-28'.match(/(?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2})/u).groups
// {y: "2018", m: "03", d: "28"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment