#Help with regex's

50 messages ยท Page 1 of 1 (latest)

sharp tinsel
#

How do I map this out into an array of role ids?

#

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

shell geyser
#

Well, what happens when you use that code?

sharp tinsel
#

don't mind the wording either ๐Ÿ˜…

shell geyser
#

Ah, yeah. m is an iterator. You need to for..of it or [โ€ฆm] spread it

sharp tinsel
#

Ah, ok. So iterator here means...?

rancid hazel
#

a thing used for iteration

arctic yokeBOT
#

mdn 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.

sharp tinsel
#

As I thought iterator means you could, well iiterate over it

rancid hazel
#

(global flag btw not operator)

sharp tinsel
#

ahhhhhh

rancid hazel
#

forEach is an api specific to arrays

sharp tinsel
shell geyser
#

for..of is a form of iteration

sharp tinsel
rancid hazel
#

what?

#

oh

#

yeah no forEach is just a typical method

rancid hazel
sharp tinsel
#

and the defintion of the gloal thingy?

rancid hazel
#

im just correcting you on the term there

sharp tinsel
#

yh so im asking for the correct term lol

rancid hazel
#

/(?flags)/flags

#

g, i, m, etc are flags

#

not operators

sharp tinsel
#

ah, flags

#

what does i and m do?

#

Thanks guys btw haha

rancid hazel
#

case __i__nsensitive
__m__ultiline

shell geyser
#

__u__nicode

rancid hazel
#

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

sharp tinsel
#

Oh awesome

#

Wow

#

Damn

rancid hazel
#

here are all the flags in js

sharp tinsel
#

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

rancid hazel
sharp tinsel
#

Oh...

rancid hazel
#

๐Ÿ˜”

sharp tinsel
#

rip js lmao

rancid hazel
#

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 ๐Ÿ˜”