Hellinfernel

Veteran
Veteran
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:
```
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:

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
8,891
Reaction score
6,695
First Language
English
Primarily Uses
RMMV
Just a quick, non-answering note, you should get in the habit of putting your code into the forum CODE tags (the </> on the edit bar).

Everything you've posted has lost its indentation and there's a place where characters have been replaced by an emoji.

It also wreaks havoc when you make loops because [i] gets turned into italics the first time and disregarded after.
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
4,646
Reaction score
3,777
First Language
EN
Primarily Uses
RMMZ
In case it helps, there's an example here regarding capture groups:
 

Hellinfernel

Veteran
Veteran
Joined
Jun 26, 2022
Messages
53
Reaction score
7
First Language
German
Primarily Uses
RMMZ
In case it helps, there's an example here regarding capture groups:
The problem was that the most explanations for named capture groups did only cover this with exec(), not matchAll(). The thing is that there is a special object for that called groups, which is supposed to allow me a really easy access to the string inside that group (matchedElement.groups.ID), but I simply struggle to find out where that object exactly is or how I have to get it. Especially since the iterator of matchAll seems to be a specialized version which only returns strings.
 

Zeriab

Huggins!
Veteran
Joined
Mar 20, 2012
Messages
1,400
Reaction score
1,612
First Language
English
Primarily Uses
Other
Look into the line where you convert the matches to an array of strings
 

Hellinfernel

Veteran
Veteran
Joined
Jun 26, 2022
Messages
53
Reaction score
7
First Language
German
Primarily Uses
RMMZ
Look into the line where you convert the matches to an array of strings
I have to admit that in the moment where I made the array.from() the first time, I wasnt sure why I needed a lambda expression if I just wanna put every iterated object into it. Will look into it today.
What irritated me a bit about that, however, was that the iterator seems to be specialized to return strings, which made me assume that I need a different kind of iterator if I really wanna have this group object. I guess I need to directly use the iterator from matchAll instead of putting it into an array first
 

Latest Threads

Latest Profile Posts

You know, I don't wish death on anything... There won't be any actual deaths in my games. I feel like it is an overused emotional trigger. But.. there is one thing I wish would just hurry up and die already. Like, seriously... why do you cling to life... Betelgeuse?! HURRY UP AND EXPLODE IN A GLORIOUS SUPERNOVA ALREADY!!
i never make fun of depressed people because even i feel it too. i know this feeling will go away but when im not at work or working on something i dislike very much the dark thoughts that enter my mind. big family definitely helps me not feel alone wen they get home tho , so thats good.
my inside A2 page is at a full rough draft now, as is my inside B page. Inside A4 has most of the walls I am using but is only about half full, and I have just started a rough draft of an inside C page.
My older brother and his family are arriving tomorrow from America for a holiday her in England. Been many years since I last seen them. Happy times.

Forum statistics

Threads
131,727
Messages
1,222,672
Members
173,471
Latest member
GGEZ555
Top