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

Add a function to get indices from a RegexMatch #53370

Closed
LilithHafner opened this issue Feb 17, 2024 · 4 comments
Closed

Add a function to get indices from a RegexMatch #53370

LilithHafner opened this issue Feb 17, 2024 · 4 comments
Labels
feature Indicates new feature / enhancement requests

Comments

@LilithHafner
Copy link
Member

LilithHafner commented Feb 17, 2024

This would provide a generic function

indices(rm::RegexMatch) = (rm.offset-1) .+ eachindex(rm.match)

which is useful, but not essential, as RegexMatch's fields are public. However, a generic function is useful because it allows packages to define something similar for their types that do not have public fields. Motivated by JuliaLang/JuliaSyntax.jl#417, and by an AbstractMatch type I'm currently defining elsewhere in a package.

@LilithHafner LilithHafner added the feature Indicates new feature / enhancement requests label Feb 17, 2024
@jariji
Copy link
Contributor

jariji commented Feb 17, 2024

  • Do you mean .+ instead of +?
  • I think indices is a confusing name since RegexMatch already has eachindex.

@LilithHafner
Copy link
Member Author

Yes

Perhaps parent_indices or source_indices?

@aplavin
Copy link
Contributor

aplavin commented Feb 18, 2024

We already have this:

julia> s = "abc 123 def"
"abc 123 def"

julia> m = match(r"\d+", s)
RegexMatch("123")

julia> parentindices(m.match)
(5:7,)

@LilithHafner
Copy link
Member Author

Thanks! I missed that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Indicates new feature / enhancement requests
Projects
None yet
Development

No branches or pull requests

3 participants