I have a question about some regular expressions.
For context, I'm currently creating Custom Commands on a Discord bot. I need to re-arrange arguments in the command.
I have this string here - bin [user] [aRG] [arg] [DEsc] and need to arrange it like so - bin [USER] $0 $1 [DESC]. I also need to make it case insensitive.
I tried to create IF statements on every possible occasion. But what I also need to keep in mind, is that I need to re-arrange it if the [DESC] comes in first then the arguments. This is what I had -
let theString = "bin [uSER] [arg] [DESc] [ARg]";
let CmdName = theString.split(" ")[0].toLowerCase();
if (theString.includes(/\[user\]/i)) CmdName += " [USER]";
if (theString.includes(/\[arg\]/i)) CmdName += " $0";
if (theString.includes(/\[arg\]/i)) CmdName += " $1";
if (theString.includes(/\[arg\]/i)) CmdName += " $2";
if (theString.includes(/\[desc\]/i)) CmdName += " [DESC]";
The above example wouldn't work anyways, if there is even one [ARG] in theString, it would include $0 $1 $2 in the CmdName variable because theString would never change.
In the above example, CmdName would need to end up like bin [USER] $0 $1 [DESC].
How can I do this effectively, possibly also iterating through it? Limiting the [ARG] value uses to three or four would also be handy.