I'm confused as to why the output is 'now ' instead of just 'now'.
mainQueryString = 'now ';
mainQueryString = mainQueryString.replace('/\s+$/g', ''); /* removing the ending space */
console.log('mainQueryString:', '\''+mainQueryString+'\'');
It still shows 'now ' with whitespace at the end.