Code:
var str = '/tip -a 20 send 20tips to chinu';
var parts = str.match(/^\/(\S+)\s+(\S+)\s+(\S+)\s*(.*)/).slice(1);
console.log(parts);
Output:
["tip", "-a", "20", "send 20tips to chinu"]
I want to change the text :
var str = '/tip 20 send 20tips to chinu';
The result should be ["tip", "20", "send 20tips to chinu"] but i am getting ["tip", "20", "send", "20tips to chinu"]
Please help me.
EDIT:
variable str contains dynamic text. It may be /tip 20 or /tip -a 20
check http://myshowcam.com/NewSite/chat-room/chinu type /help command you will get /tip command instructions.
(\S+)\s+(\S+)\s+(\S+)\s. So, by default, it matches three words