Regex filter for +/+
Regex filter for +/+
I need to search and filter a DataTable for two strings with a forward slash inbetween, such as +/+ or a/d or -/0 etc.
I have tried the following:
var escapedFilterItems = filterItems.map(function (item) {
return item.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
});
var pattern = ("\\b" + escapedFilterItems.join('\\b|\\b') + '\\b');
$(".my-table").each(function () {
$(this).DataTable().column(columnIndex).search(pattern, true, false).draw()
});
The filterItems array is set by getting the selected values of various select elements, that contain the available filter options for the current table.
So, the problem is when one of the filtered items might be the strings above, like +/+ or a/b etc.
What is the correct way to do this?
This question has an accepted answers - jump to answer
Answers
Turns out this worked in the finish for what I needed.