0

Updated: My last question was a bit confusing, I hope it is more understandable now.

What I want to achieve is to have the values stored in console.log passed to my textbox.

Let's say my list (result) looks like this:

Line 1 abc apple abc

Line 2 abc orange abc

Line 3 abc banana abc

Line 4 abc pear abc

Line 5 abc apple abc

Here is what I have tried:

textarea.value = console.log(`${match}`);

Here is my regex:

const regex = /^(.*(apple|banana).*)$/gm;
const str = result;
let m;

while ((m = regex.exec(str)) !== null) {
    if (m.index === regex.lastIndex) {
        regex.lastIndex++;
    }

    m.forEach((match, groupIndex) => {
      if(match !== 'undefined' && groupIndex > 0)
        console.log(`${match}`);
    });
}

This is the result I want in my textbox (which is now displayed in my console):

Line 1 abc apple abc

Line 3 abc banana abc

Line 5 abc apple abc
Joe Berg
  • 381
  • 3
  • 16

0 Answers0