JSFiddle - React, Tailwind, and code Playground
JavaScript
var arrayString = 'apple|ape|soap',
text = "This a nice apple tree.";
var matchedArrayItem = text.match(new RegExp("\\b(" + arrayString + ")\\b")); // please help on this
if(matchedArrayItem) {
$("body").append('The text contains the array item "'+ matchedArrayItem[0] +'".');
}
$("body").append("<br><br>" + arrayString + "<br>" + text);