Match Regex

Match Regex

by Shree Khanal

HTML

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

JavaScript

let reg = [
  "not|unfortunate|but|require|need|persists",
  "\\b(doesn|don|didn|couldn|can)(['])?(\\w{1,2})?\\b",
  "[?]",
	":\\)| :-\\)|;\\)"

];
let regex = new RegExp(reg.join("|"), 'gi');
var comment = "thanks - but I don't like magic strings ;) ?";
if (!comment.match(regex)) {
  //alert(1);

} else {

  let matches = comment.match(regex) || [];

  var msg = ' **Ignore Word-:** ';
  for (var j = 0, ln = matches.length; j < ln; j++) {
    msg += '   ---' + $.trim(matches[j].replace("'", "\'")) + '---   ';

  }
  console.log(msg);
}

//tches[j].replace("'","\'");