/ban is chat command user is some random username (with spaces) hours is for how many hours user is banned reason is explained text why user is banned (may contain spaces)
example: /ban Joe Bob Briggs 2 bad language
i need to separate all thees in 4 values;
1)/ban
2)Joe Bob Briggs
3)2
4)bad language
issue is spaces in username and reason
How could i separate all this each time no matter how many spaces are there?
I don’t see that it can be done unless there are always the same number of spaces in the name. You need to use delimiters that won’t be used in a name or reason (a comma or semicolon) or encapsulate the values.
You could split up by the last number, from there everything before until the slashed word is a name. But that’s a very fragile approach that would immediately break on several conditions, e.g. reason contains a number. So the solution from @Gandalf is way better.
So the input is invalid when it contains [] in any part that is not in the end - why is that your problem to fix invalid input? Tell the user what format you expect.
Then you first must define what you expect the user to input. But that’s less a technical question, more a conceptual. If you just want your tool to analyze any given string, try machine learning / AI.
Can’t you pass the user-id instead of the name? Then you wouldn’t need to limit what your users can have in their username, because you would only use the auto-increment id from the users table. Or do you use the user-id string for all internal stuff too?
Alter moderators chat box display so it shows the user id as well as the name? Give the mod a pop-up form to fill in?
Command line interpreters have the same issues, anything that tries to intelligently figure out which words should be grouped and which should not generally gets it wrong some of the time, and they get around it by insisting grouped words are quoted. In fact browsers are the same, there was a topic here yesterday where a html value containing spaces “didn’t work” because the code didn’t surround it in spaces. The fact that browser developers don’t try to handle this stuff tells you it must be too complex to be worth doing.