Skip to content

Instantly share code, notes, and snippets.

@itchyny
Created March 24, 2020 08:27
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 itchyny/2bfa8f4fc2c2a51995e2eb5f7c58aeba to your computer and use it in GitHub Desktop.
Save itchyny/2bfa8f4fc2c2a51995e2eb5f7c58aeba to your computer and use it in GitHub Desktop.
const opt = (s) => `${group(s)}?`;
const chars = (s) => `[${s}]`;
const group = (s) => /^\[[^\]]+\][*+]$/.test(s) ? s : `(?:${s})`;
const or = (...xs) => xs.join('|');
const many = (s) => group(`${s}*`);
const many1 = (s) => group(`${s}+`);
const integer = or('0', `[1-9]${many('[0-9]')}`);
const name = (n, s) => `(?<${n}>${s})`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment