Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regex exact match in function

my function below searches a table, currently it searches for anything like, i want it to do an exact match, could you help me out?

Thanks

function searchTable(inputVal, tablename) {
    var table = $(tablename);
    table.find('tr:not(.header)').each(function (index, row) {
        var allCells = $(row).find('td');
        if (allCells.length > 0) {
            var found = false;
            allCells.each(function (index, td) {
                var regExp = new RegExp(inputVal, 'i');
                if (regExp.test($(td).text())) {
                    found = true;
                    return false;
                }
            });
            if (found == true) $(row).show().removeClass('exclude'); else $(row).hide().addClass('exclude');
        }
    });
}
like image 512
AlexW Avatar asked Dec 28 '25 03:12

AlexW


1 Answers

Your current Regex is case insensitive. An exact match would imply case sensitivity.

var regExp = new RegExp("^" + inputVal + "$", 'i');  // case insensitive

or

var regExp = new RegExp("^" + inputVal + "$");  // case sensitive
like image 191
ic3b3rg Avatar answered Dec 30 '25 17:12

ic3b3rg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!