I took some code from the internet that searches data entered in a table (contains query) but i want it to look if text appears at the beginning of the word. here is the code

function filter(selector, query) {
    query   =   $.trim(query); //trim white space
  query = query.replace(/ /gi, '|'); //add OR for regex

  $(selector).each(function() {
    ($(this).text().search(new RegExp(query, "i")) < 0) ? $(this).hide().removeClass('visible') : $(this).show().addClass('visible');
  });
}

how can i change it to look for query at beginning of the word rather than anywhere in the word
thanks

有帮助吗?

解决方案

Use

query = "^" + query.replace(/ /gi, '|');
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top