I don't understand why this outputs 'now ' when it should output 'now'.
mainQueryString = 'now ';
mainQueryString = mainQueryString.replace('/\s+$/g', ''); /* query without the ending space */
console.log('mainQueryString:', '\''+mainQueryString+'\'');
still outputs 'now ' (with whitespace in the end).