Tokens are separated by 1 or more spaces. "A quoted string" is a single token. Anything else not beginning with a quote is a token. I tried and failed with:
var tokenre = /"[^"]*"|[^"]\S+|\s\s*/g;
For instance I want this input
[4,4]  "This is fun"
 2  2 +
 #
To tokenize as
['[4,4]', '  ', '"This is fun"', '\n ', '2', '  ', '2', ' ', '+', '\n ', '#']
This could be tested with the following code:
var result = null;
do {
    result = tokenre.exec (program);
    console.log (result);
} while (result != null);
 
    