0

Check the jquery code bellow. I want to itarate though list of text from array successMessage and find if there any match in pageHtml variable. If u check there already a matching world message but console.log(match) always returning null. Whats wrong i am doing here? JsFiddle

    const successMessage = [
      "お名前",
      "another success message"
    ];
  
  jQuery.each(successMessage, function(index, success_msg) {
    //console.log(success_msg);
    var pageHtml = "message";
    var match = pageHtml.match('/'+success_msg+'/gi');
    console.log(match);
  });
Napit
  • 31
  • 4
  • You are just building a string, you do not have a regular expression. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp is how you make a reg exp from a string – epascarello Dec 20 '21 at 15:47
  • anyone can implement with my example? this would easy to understand for me – Napit Dec 20 '21 at 15:51
  • i tried like this but not works- `var match = pageHtml.match('/'+'#'+success_msg+'#'+'/gi');` – Napit Dec 20 '21 at 15:53
  • Did you not look at the duplicate? The selected answer in the duplicate shows you what to do. It uses replace, you want to use match – epascarello Dec 20 '21 at 15:54

0 Answers0