Linkavich14 Linkavich14 - 2 months ago 9
Javascript Question

Only remove the entries that have the exact text in regex

I am currently making a table with the datatables plugin, I have made a filter using a combo box to get the results that match certain criteria, what I am having trouble is remove certain rows containing a text. For example:

In my column I will have this text in the row:



Dividend (Full (100%) Scrip Div available)
<br>
Dividend
<br>
Code Change
<br>
Dividend (Full (100%) Scrip Div available)
<br>
Consolidation
<br>
Dividend
<br>
Dividend





I want to remove all those that only have Dividend as a full word all the others should be kept.

Currently I am doing it like this:

titleColumn.search('^(?:(?!Dividend).)*$', true, false).draw();


What it does right now, it removes all the rows that contains the word Dividend, but I want to remove only the ones that have the full word and nothing else.

Thank you for your time

Answer

What you need is exact string match .You can use this as a reference. This will check for exact match and then you can remove it or whatever is your logic.

var reg = /^Dividend$/;
console.log(reg .test('Dividenda')); // false
console.log(reg .test('ba Dividend')); // false
console.log(reg .test('Dividend (Full (100%) Scrip Div available)')); // false
console.log(reg .test('Dividend a')); //false
console.log(reg .test('Dividend')); //true

In your case:

titleColumn.search(reg, true, false).draw();