ReGex to find matching keyword

by Shree Khanal

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

JavaScript

let ignorkeywords = [
  "not|unfortunate",
  "(doesn|don|didn)(?:\\')?(\\w{1,2})?",
  "need",
  "[?]"

];
let igreg = RegExp(ignorkeywords.join("|"), 'gi');
let msg = "test msg";
var comment = "this is not  edit. Need to edit. doesn't ?";
//if (!igreg.match("this is  to edit.")) {
if (!comment.match(igreg)) {
  msg += msg + ' *🚩*';
} else {
  let igmatches = comment.match(igreg) || [];
  for (var i = 0, l = igmatches.length; i < l; i++) {
    msg += '   ---' + $.trim(igmatches[i]) + '---   ';

  }
  msg += " not flagged";
}

console.log(msg);