task: apply regex to a multi-line string each like only some line contain a custom tag
only apply a substitution to the line that contain that field, and blank out all the other lines (data extraction)
current regex
.*label="([^"]*?)".*|.*
replace(s, r""".*aria-label="([^"]*?)".*|.*"""m => s"\1")
partial (simple) method is to ignore the missed capture object, and to return blank for that,
and since the half after the “or” is listed second, it blank out the line,
usability simplicity may be factors
how to i do the replace for all occurrences in the string
reference:
replace(s::AbstractString, pat=>r; [count::Integer])
Search for the given pattern pat in s, and replace each occurrence with r. If count is provided, replace at most count occurrences. pat may be a single character, a vector or a set of characters, a string, or a regular expression. If r is a function, each occurrence is
replaced with r(s) where s is the matched substring (when pat is a Regex or AbstractString) or character (when pat is an AbstractChar or a collection of AbstractChar). If pat is a regular expression and r is a SubstitutionString, then capture group references in r are replaced
with the corresponding matched text. To remove instances of pat from string, set r to the empty String ("").
Examples
≡≡≡≡≡≡≡≡≡≡
julia> replace("Python is a programming language.", "Python" => "Julia")
"Julia is a programming language."
julia> replace("The quick foxes run quickly.", "quick" => "slow", count=1)
"The slow foxes run quickly."
julia> replace("The quick foxes run quickly.", "quick" => "", count=1)
"The foxes run quickly."
julia> replace("The quick foxes run quickly.", r"fox(es)?" => s"bus\1")
"The quick buses run quickly."