-2

This is the code I got on stackoverflow also but I want to enhance it to make not case sensitive or should I change the \\b because I think it's a match symbol. What should I do?

function filter() {
    var regex = new RegExp('\\b' + this.value);
    var $els = $lbs.filter(function () {
        return regex.test($(this).text());
    });
    $lbs.not($els).hide().prev().hide();
    $els.show().prev().show();
};

input.keyup(filter).change(filter);
  • 2
    What you should do is read the manual. Start with `RegExp`. –  May 25 '15 at 07:18
  • For example, see https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/RegExp#Parameters. –  May 25 '15 at 07:27

1 Answers1

1

To do a case-insensitive search, you need to have the modifier i.

Change

 var regex = new RegExp('\\b' + this.value);

to

 var regex = new RegExp('\\b' + this.value, "i");//Added i
Zee
  • 8,420
  • 5
  • 36
  • 58
  • 1
    I suggest escaping `this.value`.. `RegExp.escape= function(s) { return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); };` should help..You can then do `RegExp.escape(this.value)` – Anirudha May 25 '15 at 06:49
  • thanks for the answer sir... but i cant vote your answer because i dont have enough reputation.. thank you again... hope i can help also – Jerbey Capoquian May 26 '15 at 10:00