I have strings like this
FOO hello world
BAR something else
BISCUIT is tasty
CAKE is tasty too
The goal is to split string once after the first word. So far I'm using this
# coffeescript
raw = 'FOO hello world'
parts = raw.split /\s/
[command, params] = [parts.shift(), parts.join(' ')]
command #=> FOO
params #=> hello world
I don't like this for two reasons:
' '
character. The real string parameters can be split by either a ' '
or a \t
and I'd like to leave the originals intact.Any ideas?
Try this out:
[ command, params ] = /^([^\s]+)\s(.*)$/.exec('FOO hello world').slice(1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With