Here’s my dilemma…
I want to be able to split a string that would look like this:
/ban @User "because I told you so"
However, the problem with using spaces, @, or quotation marks as delimiters for the string is that the user’s name can contain a wide array of special characters. AND, chances are, those special characters might be able to conflict with processing the command.
For example:
/ban @Person" "because why not"
Wouldn’t work, nor would
/ban @Person"name" "reason"
How can I accurately process something like this when any of the characters I could use to split up the string could easily be emulated by the targeted user’s name to break the command? Is this even possible at all? I’ll be honest, RegExp is kind of daunting for me to understand or look at, so if this is a simple regex fix, I apologize 🙁
Thanks a ton to a solution, I now have a working processor:
var yourRegex = /^@(.*?) "([^"]+)"$/;
Since I can already take the /ban out (other commands like /kick, etc. as it’s not exclusively this one command) I just chopped that out of the regexp. I also moved the @ symbol out since I don’t need that to target the user. Works 100% 😀
Try this:
This will give you the username in the first subpattern (with leading
@symbol, just move it outside the parentheses if you want to exclude it), and the reason in the second (without the quotes around it, move them inside the parens to include them).