#Help with regex's
50 messages · Page 1 of 1 (latest)
I have this embed and I wanna match all of the roles and then get their role ids from it
I'm trying to use this but idk how to map or forEach it
const msg = await interaction.channel.messages.fetch('1112072615981494292').catch(() => {});
if(!msg) return;
const string = msg.embeds[0].description;
const m = string.matchAll(/<@&(?<id>\d{17,20})>/g);
m.forEach((my) => console.log(my))
I'm not too sure that's the correct usage of the global operator either so please do correct me 😅, I read somethings online and that looked correct
Well, what happens when you use that code?
don't mind the wording either 😅
Ah, yeah. m is an iterator. You need to for..of it or […m] spread it
Ah, ok. So iterator here means...?
a thing used for iteration
Iterator
An Iterator object is an object that conforms to the iterator protocol by providing a next() method that returns an iterator result object. The Iterator.prototype object is a hidden global object that all built-in iterators inherit from. It provides a @@iterator method that returns the iterator object itself, making the iterator also iterable.
As I thought iterator means you could, well iiterate over it
(global flag btw not operator)
you can
ahhhhhh
forEach is an api specific to arrays
Oh, what's the definition of it 😅
for..of is a form of iteration
Ahhh, so not for object in an object
what?
oh
yeah no forEach is just a typical method
?
and the defintion of the gloal thingy?
im just correcting you on the term there
yh so im asking for the correct term lol
/(?flags)/flags
g, i, m, etc are flags
not operators
ah, flags
what does i and m do?
Thanks guys btw haha
case __i__nsensitive
__m__ultiline
__u__nicode
without multiline, ^ and $ match the start and end of the string
with multiline, they match the start and end of lines
\A and \Z match the start and end of the string regardless of the flag
Oh awesome
Wow
Damn
here are all the flags in js
Friends of mine always joked about how powerful regex's are but how much of a pain they are as well
But this is sick lmao
correction: they would if they were available in js
Oh...
😔
rip js lmao
the real pain in regex is when you're using multiple flavors of them because they each have subtle (and major) differences
the pain of not having variable-length lookbehinds 😔