Skip to content

Commit 5a5e756

Browse files
committedApr 14, 2023
update playground example
1 parent 87922c5 commit 5a5e756

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed
 

‎playground/index.mjs

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import assert from 'node:assert'
2-
import { createRegExp, exactly, digit, oneOrMore, char, wordChar } from 'magic-regexp'
2+
import { createRegExp, exactly, maybe, digit, oneOrMore, char, wordChar } from 'magic-regexp'
3+
/**
4+
* change to
5+
* import {...} from 'magic-regexp/type-level-regexp'
6+
* to try type level RegExp match results (experimental)
7+
*/
38

49
// Typed capture groups
510
const ID_RE = createRegExp(exactly('id-').and(digit.times(5).groupedAs('id')))
@@ -8,22 +13,18 @@ console.log(ID_RE, groups?.id)
813

914
// Quick-and-dirty semver
1015
const SEMVER_RE = createRegExp(
11-
oneOrMore(digit)
12-
.groupedAs('major')
13-
.and('.')
14-
.and(oneOrMore(digit).groupedAs('minor'))
15-
.and(exactly('.').and(oneOrMore(char).groupedAs('patch')).optionally())
16+
oneOrMore(digit).groupedAs('major'),
17+
'.',
18+
oneOrMore(digit).groupedAs('minor'),
19+
maybe('.', oneOrMore(char).groupedAs('patch'))
1620
)
1721
console.log(SEMVER_RE)
1822

1923
assert.equal(createRegExp(exactly('foo/test.js').after('bar/')).test('bar/foo/test.js'), true)
2024

2125
// References to previously captured groups using the group name
2226
const TENET_RE = createRegExp(
23-
wordChar
24-
.groupedAs('firstChar')
25-
.and(wordChar.groupedAs('secondChar'))
26-
.and(oneOrMore(char))
27+
exactly(wordChar.groupedAs('firstChar'), wordChar.groupedAs('secondChar'), oneOrMore(char))
2728
.and.referenceTo('secondChar')
2829
.and.referenceTo('firstChar')
2930
)

0 commit comments

Comments
 (0)