Skip to content
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

Support for named groups #29

Open
brl0 opened this issue Apr 23, 2023 · 1 comment
Open

Support for named groups #29

brl0 opened this issue Apr 23, 2023 · 1 comment

Comments

@brl0
Copy link

brl0 commented Apr 23, 2023

@mristin, First, this is a cool and helpful project. I have been working on parsing file paths and URIs and stumbled onto this.

I think it would be useful to add the ability to name the regex capture groups. I have created a PR on my fork that does this for my immediate purposes, although it would likely need some changes to integrate properly.

Is this a feature you would consider adding? If so, I might try to put together a PR.

One issue is whether this feature would be optional, which I would presume, and if so, how the configuration option should be passed down.

Another issue is duplicate group names for repeated patterns. Fortunately, the regex package handles duplicate names well, so I was able to avoid the issue for now, but Python's re module is not able to handle duplicate group names, so this feature would have limited compatibility if this issue is not addressed. Solving the issue properly is more challenging than I initially thought because of repeated nested patterns. I have a couple of thoughts, but I'd be interested in any input or ideas you might have on this.

Thanks!

@mristin
Copy link
Contributor

mristin commented Feb 15, 2024

Hi @brl0,
Please apologize for coming back to you with such a delay. The 2023 was a busy year for me.

Is this a feature you would consider adding? If so, I might try to put together a PR.

Definitely!

One issue is whether this feature would be optional, which I would presume, and if so, how the configuration option should be passed down.

What about having a separate format, python-nested-with-named-groups?

Another issue is duplicate group names for repeated patterns. Fortunately, the regex package handles duplicate names well, so I was able to avoid the issue for now, but Python's re module is not able to handle duplicate group names, so this feature would have limited compatibility if this issue is not addressed. Solving the issue properly is more challenging than I initially thought because of repeated nested patterns. I have a couple of thoughts, but I'd be interested in any input or ideas you might have on this.

I think this would be out-of-scope of the tool. We need to avoid any dependencies in the downstream code, so adding regex is not an option for us. Perhaps you can simply patch the code at the usage site with import regex as re?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants