Improved check for empty query

Improved the check for empty query using one regex, including also the trim.