(PDB-950) Added validation for regexps in queries

This commit adds a validation for regexps in queries as was proposed in PDB-950
The traversal is done by the next function down, expand-user-query. Your first point is correct though -- this approach seems like it will only be valid on v4.