Comments (5)
yes, named groups count => x=1 y=3.
you can also use [null, 1, "year", 3, "month", "day"]
, then you simply loop through the array and store names[i]: originalMatch[i]
in matches.groups, So, matches.groups["3"]
would result in "y".
from regexp-tree.
that's 1/3 of what I currently do with regexp-tree.
Your example has only named groups. You can also have unnamed groups.
You need to collect an array of both group names and indexes of regular capturing groups (set name = index).
from regexp-tree.
@hg42, good point, yeah, the second parameter should be map from group name to the index. I think unnamed groups share the same index? I.e. this matches aaa
:
/(?<foo>a)\1\k<foo>/
So perhaps:
/(x)(?<year>\d{4})-(y)(?<month>\d{2})-(?<day>\d{2})/
Would give:
new RegExpTree(/(x)(\d{4})-(y)(\d{2})-(\d{2})/, {year: 2, month: 4, day: 5});
from regexp-tree.
Transform part is done in f1233b9 and 7fb4b34.
from regexp-tree.
Local runtime support has been added in 0e6a9ff.
from regexp-tree.
Related Issues (20)
- Parser: (re)allow duplicate group names (e.g. move the check out of the parser) HOT 7
- Question about Optimization HOT 1
- Broken optimize with multiple optional whitespace `\s` HOT 4
- Optimization breaks "match all" in multiline regexps HOT 1
- Escaped hyphen in character class HOT 5
- certain meta characters shouldn't be allowed in char ranges HOT 4
- Raw bracket not reported
- Incorrect results when quantifier range unsafe integer HOT 4
- Invalid regular expression: /\${[^}]+}/: Incomplete quantifier HOT 6
- Unicode in input string is not handled HOT 5
- `UnicodeProperty` node type missing from types
- optimizer incorrectly proposes rewrite .|[\r] as [.\r] HOT 4
- Feature request: Make charClassClassrangesMerge do nothing if no ranges could be merged
- Optimizer creates unsafe Regex? HOT 1
- Incorrectly rewrite `/[a^]/` to `/[^a]/` HOT 1
- Broken optimization `/^[\p{Mc}\p{Me}\p{Mn}]$/` -> `/^[Mcen\p{}]$/` HOT 2
- False positive on optimize
- Another false-positive: `effect` => `ef{2}ect` HOT 1
- Incorrect Starting States in DFA
- [group-single-chars-to-char-class] corrupts regexp when using square bracket HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from regexp-tree.