In the process of learning JSONata I'm having difficulty figuring out how to utilize regex as a parameter. Take for example the following in a function
node:
const example = "ababbabbcc";
// Applies the string to the pattern regular expression and returns an array of objects
const expression = jsonata(`$match(${example}, /a(b+)/)`);
msg.payload = expression.evaluate();
return msg;
I am under the impression this does not work, due to the regex being wrapped in backticks, thus becoming a string.
How can I go about achieving a result such as:
[
{
"match": "ab",
"index": 0,
"groups": ["b"]
},
{
"match": "abb",
"index": 2,
"groups": ["bb"]
},
{
"match": "abb",
"index": 5,
"groups": ["bb" ]
}
]
As seen in the JSONata documentation here: String functions · JSONata