I’m trying to achieve something very simple. I’m writing a Tampermonkey script where I want to be able to input Test, test test, Test 1, T.est 2, te#st 3, test 4
and get as a result ["Test", "test test", "Test 1", "T.est 2", "te#st 3", "test 4"]
, to be used as an array. Ideally it should be compatible letters, numbers, and special characters (that aren’t commas). The result shouldn’t be ["Test", "testtest", "Test1", "T.est2", "te#st3", "test4"]
.
The current solution I have is
const TESTOUTPUT = 'Test, test test, Test 1, T.est 2, te#st 3, test 4'.match(/[^,s?]+/g);
console.log(TESTOUTPUT);
The output is ["Test", "test", "test", "Test", "1", "T.est", "2", "te#st", "3", "test", "4"]
, so it’s inserting commas after every word and erasing every whitespace between them.
Other solutions I’ve found (like this one and this one) are separating elements that don’t have any space between them before or after the commas (so their input is Test, testtest, Test1, T.est2, te#st3, test4
)