-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: named capture groups and reference (#66)
- Loading branch information
1 parent
65022ee
commit 57f7265
Showing
21 changed files
with
386 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{} | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import './test-utils/to-equal-regex'; | ||
import './test-utils/to-match-groups'; | ||
import './test-utils/to-match-all-groups'; | ||
import './test-utils/to-match-named-groups'; | ||
import './test-utils/to-match-all-named-groups'; | ||
import './test-utils/to-match-string'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { | ||
any, | ||
buildRegExp, | ||
capture, | ||
charClass, | ||
charRange, | ||
digit, | ||
oneOrMore, | ||
ref, | ||
zeroOrMore, | ||
} from '..'; | ||
|
||
test('example: html tag matching', () => { | ||
const tagName = oneOrMore(charClass(charRange('a', 'z'), digit)); | ||
const tagContent = zeroOrMore(any, { greedy: false }); | ||
|
||
const tagMatcher = buildRegExp( | ||
[ | ||
'<', | ||
capture(tagName, { name: 'tag' }), | ||
'>', | ||
capture(tagContent, { name: 'content' }), | ||
'</', | ||
ref('tag'), | ||
'>', | ||
], | ||
{ ignoreCase: true, global: true }, | ||
); | ||
|
||
expect(tagMatcher).toMatchAllNamedGroups('<a>abc</a>', [{ tag: 'a', content: 'abc' }]); | ||
expect(tagMatcher).toMatchAllNamedGroups('<a><b>abc</b></a>', [ | ||
{ tag: 'a', content: '<b>abc</b>' }, | ||
]); | ||
expect(tagMatcher).toMatchAllNamedGroups('<a>abc1</a><b>abc2</b>', [ | ||
{ tag: 'a', content: 'abc1' }, | ||
{ tag: 'b', content: 'abc2' }, | ||
]); | ||
|
||
expect(tagMatcher).not.toMatchString('<a>abc</b>'); | ||
|
||
expect(tagMatcher).toEqualRegex('<(?<tag>[a-z\\d]+)>(?<content>.*?)<\\/\\k<tag>>'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.