How do I pass dynamic string in $match pattern in Jsonata?

When I try to pass value directly in pattern /2020-04-01,ARS,AED/ is working but when I try to pass through variables I'm not getting the output

$temp1:=ExecutionDate;
$temp2:=Currency;
$temp3:=ConvertToCurrencyISO;
$response_text:="2020-04-01,ARS,AED,.0570575091\n2020-04-01,ARS,AUD,.0252416065"
$response_index:=$match($string($response_text),/$temp1,$temp2,$temp3/).index;

Upvotes: 0

Views: 784

Answers (1)

Andrew Coleman
Andrew Coleman

Reputation: 1559

You can use the $eval function to dynamically create a regex. E.g.:

(
    $temp1:=ExecutionDate;
    $temp2:=Currency;
    $temp3:=ConvertToCurrencyISO;
    $regex := $eval('/' & $temp1 & ',' & $temp2 & ',' & $temp3 & '/');
    $response_text:="2020-04-01,ARS,AED,.0570575091\n2020-04-01,ARS,AUD,.0252416065";
    $response_index:=$match($response_text,$regex);
)

See https://try.jsonata.org/hrE61rzJt

Upvotes: 1

Related Questions