regex – Dataweave how to use variables in regular expression
I want to use a regular expression in Mulesoft Dataweave and substitute some values by using variables.
I have this code which excecutes fine in Dataweave:
"1000000087" replace /^(.{3}).(.{6})$/ with ($[1] ++ "H" ++ $[2])
//output
"100H000087"
I want to substitute value 3 and 6 for the number of digits with variables.
I have tried this:
var prefix = 3
var suffix = 6
"1000000087" replace /^(.{prefix}).(.{suffix})$/ with ($[1] ++ "H" ++ $[2])
This gives this error:
invalid Regex: Illegal repetition near index 2
^(.{prefix}).(.{suffix})$
^
26| "1000000087" replace /^(.{prefix}).(.{suffix})$/ with ($[1] ++ "H" ++ $[2])
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Location:
main (line: 26, column:22)
How to solve this ?
Read more here: Source link
