I’m trying to create a regex search in Datatables which matches a user who belongs to all selected groups.
Example:
User A belongs to Delta, Year 6, Year 6 Netball Team
User B belongs to Delta, Year 6 Netball Team
If Delta and Year 6 are selected as filters, only user A should show in the table. The problem I’m having is that both users are showing when these filters are selected. I don’t think the regex is matching exact strings and, after looking through multiple other answers, I don’t seem to be able to get it to do so.
My solution:
if (!this.items.length) {
table.column(i).search('');
} else {
let regex = '^';
this.items.forEach(v => regex += `(?=.*\b${v}\b)`);
regex += '.*$'
table.column(i).search(regex, true, false, true)
}
Which results in: ^(?=.*bDeltab)(?=.*bYear 6b).*$
However, as shown, the user belonging to Delta,Year 6 Netball Team is still being returned.