Skip to content

Instantly share code, notes, and snippets.

@amithegde
Last active August 29, 2015 13:57
Show Gist options
  • Save amithegde/9909821 to your computer and use it in GitHub Desktop.
Save amithegde/9909821 to your computer and use it in GitHub Desktop.
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>
<p>enter query in the format: colNam2: value. value can have double quotes for compound query</p>
<input type="text" id="queryText"/>
<div id="result"></div>
</body>
<script>
$(function(){
$('#queryText').keyup(function(){
$('#result').html('');
var query = $('#queryText').val();
if(query != ''){
var queryList = parseGetFilterQuery(query);
if(queryList.length>0)
{
queryList.forEach(function(item){
$('#result').append('<p>' + item.ColName + ' : ' + item.ColQuery+ '</p>');
});
}
}
});
});
function parseGetFilterQuery(query)
{
var queryList = [];
var colNames = query.match(/\w+:/g);
if(colNames.length > 0)
{
for(var colIndex = 0; colIndex < colNames.length; colIndex++)
{
var regex;
var match;
if(colIndex< colNames.length - 1)
{
regex = new RegExp(colNames[colIndex] + '(.+)' + colNames[colIndex+1]);
match = regex.exec(query);
}else
{
regex = new RegExp(colNames[colIndex]+'(.+)');
match = regex.exec(query);
}
if(match && match.length>0)
{
//remove leading and trailing space form the match vlaue and push to list only if col value is not a whitespace
queryList.push({ColName: colNames[colIndex], ColQuery: match[1].replace(/["]/g, '')});
}
}
}
return queryList;
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment