You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Regex docs provide indexing with Symbol, where the symbol is the name of the capture group.
What is lacking is a way to retrieve the capture group names from either a Match or just the Regex itself (from the docs).
s ="aaa bbb ccc"
r =r"(?<a>.*) (?<b>.*) (?<c>.*)"
m =match(r, s) # I don't think there is a way to retrieve the symbols [:a, :b, :c] from this or `r`
One has to know about Base.PCRE.capture_names(m.regex.regex).
The context in which this arose was wanting to easily construct a DataFrame from a Vector{RegexMatch} where the capture group names become the column names. Thanks to @pdeffebach for finding the capture_names function for me.
From the master branch, we now have a keys function.
s ="aaa bbb ccc"
r =r"(?<a>.*) (?<b>.*) (?<c>.*)"
m =match(r, s)
d =Dict(keys(m) .=> m)
# Dict{String, SubString{String}} with 3 entries: "c" => "ccc" "b" => "bbb" "a" => "aaa"
I was looking into doing this and I noticed that none of the RegexMatch functions (or RegexMatch itself) are documented. Should I go ahead and add documentation for all of these?
The Regex docs provide indexing with Symbol, where the symbol is the name of the capture group.
What is lacking is a way to retrieve the capture group names from either a Match or just the Regex itself (from the docs).
One has to know about
Base.PCRE.capture_names(m.regex.regex)
.The context in which this arose was wanting to easily construct a
DataFrame
from aVector{RegexMatch}
where the capture group names become the column names. Thanks to @pdeffebach for finding thecapture_names
function for me.This should be a simple PR to add a line to https://docs.julialang.org/en/v1/manual/strings/#Regular-Expressions mentioning it.
I may get to it, I may not xd
The text was updated successfully, but these errors were encountered: