I'm using this code to get items that match a particular keyword.
var match_data = function(search_str, items) {
var reg = new RegExp(search_str.split('').join('\\w*').replace(/\W/, ""), 'i');
return items.filter(function(item_data) {
if (item_data.match(reg)) {
return item_data;
}
});
};
Is there any way I can get the index of the matched item as well ?
Also I keep getting this warning when my search string comtains \ anywhere in it:
Uncaught SyntaxError: Invalid regular expression: /iw*m\w*\/: \ at end of pattern(…)
Can you guys please help me solve this error as well.
Thanks in advance.
indexOf(val)function to get the index of value from the array.