Home > Enterprise >  How do I match the first occurrence of a regular expression in a Julia string and store the match in
How do I match the first occurrence of a regular expression in a Julia string and store the match in

Time:01-17

ChatGPT (which has actually been quite helpful assisting me with with Julia) gave me the code below, but it produces this error: invalid using path: "Regex" does not name a module

using Base.Regex

string = "The quick brown fox jumps over the lazy dog."
regex = r"\w "

for match in eachmatch(regex, string)
    println(match.match)
end

CodePudding user response:

Just omit the Base.Regex (and note that the mentioned platform claims that 'five' has 5 letters. I mean, it's not precise):

julia> string = "The quick brown fox jumps over the lazy dog.";

julia> regex = r"\w ";

julia> for match in eachmatch(regex, string)
           println(match.match)
       end
The
quick
brown
fox
jumps
over
the
lazy
dog
  • Related