javascript search for words in sentence examples
var myString = document.getElementById("str").innerHTML;
var myWord = document.getElementById("txt1").value;
var myPattern = new RegExp('(\\w*'+myWord+'\\w*)','gi');
var matches = myString.match(myPattern);
if (matches === null)
{
document.getElementById("demo").innerHTML = "No results"; // Any message or empty
return;
}
document.getElementById("demo").innerHTML = matches + " - " + matches.length + " result(s) found.";