Skip to content

Commit 7fe1703

Browse files
committed
docs: update playground with a better example
1 parent b2b7876 commit 7fe1703

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

playground/index.mjs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import assert from 'node:assert'
2-
import { createRegExp, exactly, digit } from 'magic-regexp'
2+
import { createRegExp, exactly, digit, oneOrMore, char } from 'magic-regexp'
33

4-
const regExp = createRegExp(exactly('foo/test.js').after('bar/'))
5-
assert.equal(regExp.test('bar/foo/test.js'), true)
4+
// Typed capture groups
5+
const ID_RE = createRegExp(exactly('id-').and(digit.times(5).as('id')))
6+
const groups = 'some id-23490 here we go'.match(ID_RE)?.groups
7+
console.log(ID_RE, groups?.id)
68

7-
console.log(regExp)
9+
// Quick-and-dirty semver
10+
const SEMVER_RE = createRegExp(
11+
oneOrMore(digit)
12+
.as('major')
13+
.and('.')
14+
.and(oneOrMore(digit).as('minor'))
15+
.and(exactly('.').and(oneOrMore(char).as('patch')).optionally())
16+
)
17+
console.log(SEMVER_RE)
818

9-
const typedCaptureGroup = createRegExp(exactly('id-').and(digit.times(5).as('id')))
10-
const groups = 'some id-23490 here we go'.match(typedCaptureGroup)?.groups
11-
12-
console.log(typedCaptureGroup, groups?.id)
19+
assert.equal(createRegExp(exactly('foo/test.js').after('bar/')).test('bar/foo/test.js'), true)

0 commit comments

Comments
 (0)