1var myString = document.getElementById("str").innerHTML;
2var myWord = document.getElementById("txt1").value;
3var myPattern = new RegExp('(\\w*'+myWord+'\\w*)','gi');
4
5var matches = myString.match(myPattern);
6
7if (matches === null)
8{
9 document.getElementById("demo").innerHTML = "No results"; // Any message or empty
10 return;
11}
12
13document.getElementById("demo").innerHTML = matches + " - " + matches.length + " result(s) found.";
14