JSFiddle - React, Tailwind, and code Playground

by Alexey Ukolov

JavaScript

const faq = [
  "<p><ul>\n<li>•  Download the App from <a href=\"https://itunes.apple.com/US/app?mt=8%29\" target=\"_blank\">AppStore</a> or <a href=\"https://play.google.com/store/apps/details?id=\" target=\"_blank\">Google Store</a></li>\n                        <li>•  Issue a virtual card within the app</li></ul>.</p>",
  "<p><ul>\n<li>•  Download the App from <a href=\"https://itunes.apple.com/US/app?mt=8%29\" target=\"_blank\">AppStore</a> or <a href=\"https://play.google.com/store/apps/details?id=\" target=\"_blank\">Google Store</a></li>\n                        <li>•  Issue a virtual card within the app</li></ul>.</p>",
  "<p><ul>\n<li>•  Download the App from <a href=\"https://itunes.apple.com/US/app?mt=8%29\" target=\"_blank\">AppStore</a> or <a href=\"https://play.google.com/store/apps/details?id=\" target=\"_blank\">Google Store</a></li>\n                        <li>•  Issue a virtual card within the app</li></ul>.</p>",
];

const replace = (search, replace, html) => {
  return html.replace(search, replace);
}

let searchText = 'app';
let searchPattern = new RegExp(`(?!<a[^>]*?>)(${searchText})(?![^<]*?</a>)`, 'gi');
let replaceText = 'Foo';

console.log(faq.map(replace.bind(null, searchPattern, replaceText)));