1
votes

how can I use regex groups to extract data from a string in dataweave 1.0?

%var sampleString="3,2,0"

{
"groups":using(regexMatch= sampleString scan /^(?<grp1>\d{1}),(?<grp2>\d{1}),(?<grp3>\d{1})$/) {
        "group1": regexMatch["grp1"] ????? Any way to get the grp1 value by group name,
        "group2": regexMatch[0][2] //works,
        "group3": regexMatch[0][3] //works
    }
}
1

1 Answers

0
votes

Unfortunately the scan function returns an array of arrays (doco), not an array of maps, so the only way you can interrogate it is via numeric index. Named capturing groups are treated as any other group in the end (i.e. the name is ignored).