-
-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add named capturing groups to gleam/regex.Match #663
Comments
How would we handle groups with no names? |
named groups can be |
here's how javascript handles it >> /(?<type_of>new|old)\s+(\w+)/.exec("new match_type")
Array(3) [ "new match_type", "new", "match_type" ]
0: "new match_type"
1: "new"
2: "match_type"
groups: Object { type_of: "new" }
type_of: "new"
index: 0
input: "new match_type"
length: 3
<prototype>: Array [] |
due to how Erlang handles matches though, it may be necessary to instead include desired group names in 1> re:run("new match_type", "(?<type_of>new|old)\\s+(\\w+)").
{match,[{0,14},{0,3},{4,10}]}
2> re:run("new match_type", "(?<type_of>new|old)\\s+(\\w+)", [{capture, ["type_of"], list}]).
{match,["new"]} |
I see now gleam/regex is meant to be a port of Elm's Regex package and they unfortunately don't have a way to extract capturing group names either. Straying from this would have to be a decision. 🤷 |
It's not a port, similarity is incidental |
As it is now, you have the ability to write named capturing groups, but those results don't appear in the list of matches returned from
regex.scan
.I propose
Match
have the following signature:So now running something like this
would give you this
If the concern is this may break existing used regex, possibly a new added option (which will still break existing compiled regex) or a new
groups
function can be added that returns just a list of tuples of group name and submatches.The text was updated successfully, but these errors were encountered: