I’m quite new to Julia using Python and R before. I want to populate a new column in a DataFrame with data extracted from an existing column using Regex. I apply the function match, broadcasting and a regex to extract the information. I can populate the new column with the RegexMatch object, only. I want to get the string from the RegexMatch object. But, the function m.match (https://docs.julialang.org/en/v1/manual/strings/#Regular-Expressions-1) doesn’t work in combination with broadcasting.
using DataFrames
using Random
series = rand(["110-bla","599-tag"],6)
test = DataFrame(s1 = series)
test.s2 = match.(r"[0-9]*",test.s1)
result=
Row │ s1 │ s2 │
│ │ String │ RegexMatch │
├─────┼─────────┼───────────────────┤
│ 1 │ 110-bla │ RegexMatch(“110”) │
│ 2 │ 599-tag │ RegexMatch(“599”) │
│ 3 │ 110-bla │ RegexMatch(“110”) │
│ 4 │ 599-tag │ RegexMatch(“599”) │
│ 5 │ 110-bla │ RegexMatch(“110”) │
│ 6 │ 110-bla │ RegexMatch(“110”)
for a single value I can extract the string (here “110”) correctly
match(r"[0-9]*","110-bla").match
but when I try to broadcast, I get an error message “type Array has no field match”
test.s2 = match.(r"[0-9]*",test.s1).match
Thanks a lot in advance for your help!