Examples


Quick-and-dirty semver

import { createRegExp, exactly, oneOrMore, digit } from 'magic-regexp'createRegExp(  oneOrMore(digit)    .as('major')    .and('.')    .and(oneOrMore(digit).as('minor'))    .and(exactly('.').and(oneOrMore(char).as('patch')).optionally()))// /(?<major>(\d)+)\.(?<minor>(\d)+)(\.(?<patch>(.)+))?/

References to previously captured groups using the group name

import assert from 'node:assert'import { createRegExp, word, char, oneOrMore } from 'magic-regexp'const TENET_RE = createRegExp(  wordChar    .as('firstChar')    .and(wordChar.as('secondChar'))    .and(oneOrMore(char))    .and.referenceTo('secondChar')    .and.referenceTo('firstChar'))// /(?<firstChar>\w)(?<secondChar>\w).+\k<secondChar>\k<firstChar>/assert.equal(TENET_RE.test('TEN<==O==>NET'), true)