📅  最后修改于: 2022-03-11 15:04:13.845000             🧑  作者: Mango
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.";