如何在Jquery Datatables的fnFilter中对多个值进行正则表达式匹配?

时间:2021-11-01 14:25:04

Im' trying to do a filter with multiple values in Jquery datatable but the regex expression is failing.

我试图在Jquery数据表中使用多个值进行过滤,但正则表达式失败。

This works:

// $(this).val()[0] = "Testing string";

test.fnFilter("^" + $(this).val()[0] + "$", i, true, true);

This filters all the rows to value "Testing string" for this column.

But when I try to do this on multiple values, it is not working properly :

但是当我尝试在多个值上执行此操作时,它无法正常工作:

// inputValues = "(Testing string|Hello world)"

dossierlijst.fnFilter("^" + inputValues + "$", i, true, true);

2 个解决方案

#1


0  

What does "(Testing string)|(Hello world)" do? I'm heavily relying upon rubular.com for regular expressions myself. Since that eats both groups, maybe JS doesn't like that the brackets are on the outside?

“(测试字符串)|(Hello world)”做什么?我自己在很大程度上依赖rubular.com来表达正则表达式。既然吃了两个组,也许JS不喜欢括号在外面?

#2


0  

The solution was to put ^ before and $ after every value.

解决方案是在每个值之前加上^和$。

// inputValues = "(^Testing string$)|(^Hello world$)"

dossierlijst.fnFilter(inputValues, i, true, true);

#1


0  

What does "(Testing string)|(Hello world)" do? I'm heavily relying upon rubular.com for regular expressions myself. Since that eats both groups, maybe JS doesn't like that the brackets are on the outside?

“(测试字符串)|(Hello world)”做什么?我自己在很大程度上依赖rubular.com来表达正则表达式。既然吃了两个组,也许JS不喜欢括号在外面?

#2


0  

The solution was to put ^ before and $ after every value.

解决方案是在每个值之前加上^和$。

// inputValues = "(^Testing string$)|(^Hello world$)"

dossierlijst.fnFilter(inputValues, i, true, true);