Search code examples
tablesorter

possible syntax to search wildcard to fixed length with tablesorter


Using tablesorter is it possible to search a column using wildcards to a fixed length?

ie having the following

aa
aaa
aaaa
ab
aba
abaa

is there syntax such as =a? that would return only

aa
ab

thx Art


Solution

  • When you use the ? character in the filter widget, it is actually replacing the ? with a \S{1}. The regular expression used to search the column becomes /a\S{1}/ which finds aaaa because there are two separate matches of a? (RegExr demo).

    The filter widget will accept regular expressions. To get the exact match you are wanting, you'll need to use the word boundary anchor (\b) and surround the value (/\ba\S\b/ or /\ba.\b/) (regExr demo).

    Here is a tablesorter demo

    // this example will only target the first column
    $('table').trigger('search', [[ "/\ba\S\b/" ]]);