feat: named capture groups and reference #66
Merged
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Summary
capture(...)
generates a Capturing Group ((...)
in regex syntax). When callingString.match()
orRegex.exec()
, the result will beArray
-like object. At index0
it will hold whole matched regex, at indexes1
and later it will hold values captured by consecutive capturing groups in the regex.capture(..., { name: 'aaa' })
generates a Named Capturing Group ((?<aaa>...)
in regex). It results are also available on thematch()
result at specified indexes like regular Capturing Group. In addition to that, match result will also expose matched results by name, underresult.group.aaa
, etc. for each Named Capturing Group in the regex.Captured value can also be used during matching using Backreferences. Backreference can either refer to Capuring Group order (
\1
,\2
, etc) or name (\k<aaa>
, etc). In TS Regex Builder to use backreference we need to do following:Alternatives
Base idea:
Alternative 1: separete
name
andref
options:Alternative 2: explicitly define
namedCapture
:Test plan