I'm trying to capture a certain structured data, and I need it to capture a certain group as long as there are possibilities.
The format of the data is as follows:
foo01 @ key1 | value1 # keyN | valueN
Where the first group consists of a numeric alpha value, separating the other groups with the character @
, my interest is to get only the foo01
in the first group.
The second group is what is repeated, where Attribute and value are separated by |
and the other attributes are separated by #
, after that there is no more information only attributes in the format "key1 | value1 # keyN | valueN ".
Below you can see what I started to do, but I was not able to capture all of the attributes separately.
const regex = /(^[a-zA-Z0-9_]*@)([a-zA-Z0-9_]*\|[a-zA-Z0-9_]*)/g;
const str = 'foo01@chave1|valor1#chaveN|valorN';
let m;
while ((m = regex.exec(str)) !== null) {
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
m.forEach((match, groupIndex) => {
console.log('Encontrado, grupo ${groupIndex}: ${match}');
});
}
I would like to know how to capture all occurrences of "key1 | value1 # keyN | valueN" within a string independent of the amount present in the string.