3 ms·
That supposes that your values either don't have embedded white spaces or are completely numeric... So it's not really equivalent. > '\t1 ;2 a;3;4;5;6;7;8
by pygy_ 9y ago
That supposes that your values either don't have embedded white spaces or are completely numeric... So it's not really equivalent.
> '\t1 ;2 a;3;4;5;6;7;8;9\r\n;10\n'.split(';').map(Function.prototype.call, String.prototype.trim)
[ '1', '2 a', '3', '4', '5', '6', '7', '8', '9', '10' ]
> '\t1 ;2 a;3;4;5;6;7;8;9\r\n;10\n'.match(/[^;\s]+/g)
[ '1', '2', 'a', '3', '4', '5', '6', '7', '8', '9', '10' ]
> '\t1 ;2 a;3;4;5;6;7;8;9\r\n;10\n'.match(/\d+/g)
[ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ]
Edit (re. your edit):
> '\t1 ;2 a;3;4;5;6;7;8;9\r\n;10\n'.trim().split(/[;\s]+/)
[ '1', '2', 'a', '3', '4', '5', '6', '7', '8', '9', '10' ]