title: How to find name from string using Regex in NodeJs
body: <p>Here is my code , i have written separate function for regex to extract name pattern, passing Regex Pattern with two strings to the function, function matches either one pattern from two input string or it will return 'No_Value'.</p>
  
  <pre><code> function getName(narration_1, narration_2, regex) {
  try {
      // regex = JSON.parse(regex);
      regex = regex.find((item) =&gt; { console.log("Item", item); return (new RegExp(item, 'ig').test(narration_1) === true || new RegExp(item, 'ig').test(narration_2) === true)});
      console.log("Regex", regex);
      let narration = (!!regex) ? (new RegExp(regex, 'ig').test(narration_1) ? narration_1 : narration_2) : null;
      let name = (!!narration &amp;&amp; narration.match(regex)) ? (!narration.match(regex)[1] ? 'NO_VALUE' : narration.match(regex)[1].trim()) : 'NO_VALUE';
      console.log(name);
      return name;
  } catch(e) {
      console.log("Err", e);
      // throw new Error(e);
  
  }
   }
  
  let string1 ="OPERATION"
  let string2 = "退回自動轉賬 WRITE SOMEOPERATIONS TO MR . MANOJ-THOMAS"
  let regex =  ["MR (.*?) (?:[a-zA-Z]+[0-9]|[0-9]+[a-zA-Z])"];
  getName(string1, string2, regex);
  </code></pre>
  
  <p>I want to extract name from above string 2 MANOJ-THOMAS however the name appears it can also need to match "Mr.","MR .",MR.","MR.  ".</p>