I'm trying to find all the matches in a string that follow a particular pattern like this {{any thing here}}
, but I'm not able to extract all the matches properly. Don't know what I'm doing wrong. Below is the code that I have tried so far.
const string = `You have been identified in <span class="alert underline">{{db.count}}</span> breaches with <span class="alert underline">{{db.data_types}}</span> unique data types.`;
I have tried the following methods:
Method 1
const matches = /{{(.*?)}}/igm.exec(value);
console.log(matches);
Output:
{
0: "{{db.count}}",
1: "db.count",
index: 58,
input: "You have been identified in <span class="alert und…line">{{db.data_types}}</span> unique data types.",
groups: undefined
}
Method 2
const matches = RegExp('{{(.*?)}}', 'igm').exec(value);
console.log(matches);
Output:
{
0: "{{db.count}}",
1: "db.count",
index: 58,
input: "You have been identified in <span class="alert und…line">{{db.data_types}}</span> unique data types.",
groups: undefined
}
Method 3
const matches = value.match(/{{(.*?)}}/igm);
console.log(matches);
Output:
[
"{{db.count}}",
"{{db.data_types}}"
]
Expected output:
[
'db.count',
'db.data_types'
]
If anyone has faced the same issue, please help. Thanks in advance.