-1

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 with is to 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, the others should be kept.

Currently I am doing it like this:

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

What it does right now is to remove 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.

Wilder Pereira
  • 2,039
  • 3
  • 21
  • 27
Linkavich14
  • 173
  • 3
  • 12
  • Do you want to allow for white-space in the row (and thus remove, e.g., `"Dividend "`)? – nnnnnn Sep 22 '16 at 01:38
  • Hi, not really, the white spaces are removed before, so just need to remove the rows that contain "Dividend" any other words that have Dividend and some extra text must stay – Linkavich14 Sep 22 '16 at 01:47

2 Answers2

1

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();
Cyclotron3x3
  • 1,968
  • 19
  • 34
  • Hi @Cyclotron3x3, I just found out how to do it, but I got it thanks to you and dave. It works correctly if I send it like this: titleColumn.search('^(?:(?!^Dividend$).)*$', true, false).draw(); – Linkavich14 Sep 22 '16 at 02:25
  • @Linkavich14 I think I found a simpler version of your regex. Works for me in Perl anyway. – dave Sep 22 '16 at 02:30
0

In essence, we wish to look for the word Dividend bound by the start and end of line. However, because you wish to exclude these lines we use a lookaround:

titleColumn.search('^(?!Dividend$)', true, false).draw();
dave
  • 10,691
  • 5
  • 40
  • 57
  • Hi Dave, what I need is to remove the ones that have the full word Dividend and has nothing else besides the word and keep all the others – Linkavich14 Sep 22 '16 at 01:44
  • I realised that, but wasn't paying attention to the effect of the search. I'll adjust my answer. – dave Sep 22 '16 at 02:16