#replaceAll

33 messages · Page 1 of 1 (latest)

devout cave
#

@wraith saffron

wraith saffron
#

Hi, you should also post what you wanna do in the description of this post so other helpers can help cuz as I stated, I am not a regex expert, just know basic regex so someone may have a better regex for you

devout cave
#

okay

#

but, what you gave, worked

#

so, how would i make this work when sending?

wraith saffron
# devout cave <@493230285278937098>

Now, you jus extract the fields from the string (title, description, etc) and input it into an embed builder. Although, I would've recommended creating a modal so the user can input the fields individually and you won't have to extract from a single string. To do this tho, it looks like we're gonna have to match content between {} but that can cause errors if we use regex

#

Have you found a way on how you'd extract the fields from the string or do we need to do that?

devout cave
wraith saffron
#

Alright well, this part is gonna be the hardest

devout cave
wraith saffron
#

Well, you can use regex yet again but I can't think of a regex for this without mistakenly matching the wrong things

devout cave
#

you don't think there is another way to change for this?

wraith saffron
# devout cave if that's the case, then i'd have to check for a lot to just send the embed. if ...

Yeahh, you have to match each field individually. You can try sumn like

const str = "{embed}$v{title: title here}$v{field: field title && field value}$v{field: title && value}";

const title = str.match(/\{title: .[^\}]*/);
//returns ["{title: title here"]

//and for fields
const fields = str.match(/\{field: .[^\}]*/g);

//returns ["{field: field title && field value", "{field: title && value"]

But I'm not sure if it'll cause problems, I'm writing this off the top right now

#

So title is supposed to match something starting with {title: and continue to match until the nearest }

#

Fields is the same, difference is it matches everything passing the condition

devout cave
#

and im pretty sure, itll be harder to get author icon & url same with footer because this is how you set an icon and url with my parser
{embed}$v{author: <text> && <icon url> && url}

wraith saffron
devout cave
#

ok

wraith saffron
devout cave
#

ok let's test something

#

how would we send the embed like in the channel 😭

#

this is confusing to me because ive never tried this

wraith saffron
devout cave
#

basically, yes

wraith saffron
#

Also, I updated the message with the return values, I can't give you anymore code, I gave you that because it seemed fun to me so I wanted to try it lol but as I said, the rest doesn't really take much effort. When you get the return array for the title, if the array has an element in it, jus do array[0] to get the first element or if there's more than one then tell the user "You inputted 2 titles" or something yk, to get the title jus slice off the {title: part using .slice()

#

And use that logic for the rest

#

As for things that take two values like fields and stuff, do everything I jus said but with the return string, do .split("&&") and the first element in the array, if there is, would be the title and the second element would be the value, again, if there is

devout cave
#

ok

wraith saffron
#

As for the errors like if the user inputted a title and not a value, you should be able to do those for yourself, not rlly difficult. Try something and lemme see what you got and if you test it and you got an error, come tell me and I'll help

#

Ping me if you want to, I have like 3k pings so now pings dont rlly bother me but I'll see the 1 under the djs server if I'm online