Is it possible to filter/search by not matching a specific character in regex?
Is it possible to filter/search by not matching a specific character in regex?
We are using DT 1.10. I have seen a few others ask this question but with no replies which leads me to suspect it cannot be done, but perhaps there is a way. Is it possible to search a column and return all records which do not contain a plus sign "+"? This works outside of DT: ^((?!\+).)*$
however it does not work with .search(). We use column header filters extensively with great success with positive regex matches, however this negative matching filter we cannot get to work in Datatables. Thanks in advance for any help.
This question has an accepted answers - jump to answer
Answers
In general there is no problem with regex not in datatables filtering, in my yadcf plugin there is an option for such "not" filtering, you can see it action in this showcase page notice the 4'th column (values) there is a checkbox (called "exclude") that allow you to do the "not" filtering.
Anyway you should escape your ((?!+).) expression ,
something like this:
In part that was an error in the forum. For some reason it is stripping out escapes unless they are in Markdown code tick marks... I've added them now.
However, that you say is absolutely true - DataTables creates the regex using
new RegExp(...)
- so it does need another escape:'^((?!\\+).)*$'
.Example.
I think for 1.11 passing a regex into
search()
might be quite a nice feature.Allan
Thank you very much Daniel and Allan, yes in fact the missing additional backslash was the problem, this works great now.
Thanks again, appreciate it.
Tammy