- Joined
- Jun 26, 2022
- Messages
- 53
- Reaction score
- 7
- First Language
- German
- Primarily Uses
- RMMZ
As you probably noticed from my other threads, i am currently working at a Plugin and i actually make good progress. Now I want to utilize the named capture groups, because of how it makes it easier to extract the information I need from the notetag.
Unfortunately, i wasn't able to find out how to get the "group" object of the objects I got from the Iterator from matchAll(). So my question would be how to analyze the content of a named capture group in JavaScript.
The for this part relevant Code is:
```
```
What did i expected?
That the matechedElement.group.xxx returns the content of the group that is named xxx.
What was the result?
rmmz_managers.js:2032 TypeError: Cannot read property 'ID' of undefined
P.s asked that thing already on stackoverflow, 2 minutes later it was deleted because allegedly the same as other questions, but they simply hadn't the answer i needed. Most of them didn't showed how to use it with match all, which is the thing i need.
Unfortunately, i wasn't able to find out how to get the "group" object of the objects I got from the Iterator from matchAll(). So my question would be how to analyze the content of a named capture group in JavaScript.
The for this part relevant Code is:
```
Code:
const regex1new = /(?<ItemCategory>Item|Armor|Weapon)\s*:\s*(?<ID>\d+)\s*(?<Weight>w:(?<WeightFactor>\d+))?/gm;
let foundTagEntrysList = Array.from(this.enemy().meta.HellsCommonDropList.matchAll(regex1new), entry => entry[0]); //If you wanna reproduce this, just replace this.enemy().meta.HellsCommonDropList with a string
newTagsAnalyser();
function newTagsAnalyser() {
foundTagEntrysList.forEach(matchedElement => {
let Item;
let Weight;
let ID = matchedElement.groups.ID;
switch (matchedElement.groups.ItemCategory) {
case "Item":
Item = $dataItems[ID];
break;
case "Weapon":
Item = $dataWeapon[ID];
break;
case "Armor":
Item = $dataArmor[ID];
break;
default:
break;
}
if (typeof matchedElement.groups.Weight !== 'undefined'){
Weight = matchedElement.groups.WeightFactor;
}
commonItemDataMap.set(Item, Weight);
});
}
```
What did i expected?
That the matechedElement.group.xxx returns the content of the group that is named xxx.
What was the result?
rmmz_managers.js:2032 TypeError: Cannot read property 'ID' of undefined
P.s asked that thing already on stackoverflow, 2 minutes later it was deleted because allegedly the same as other questions, but they simply hadn't the answer i needed. Most of them didn't showed how to use it with match all, which is the thing i need.
Last edited: