Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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.";
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to remove selected characters from a string in javascript 
Javascript :: unzip file electronjs 
Javascript :: opencage reverse geocoding example 
Javascript :: flutter http get json to map 
Javascript :: abrir dialog angular material 
Javascript :: javascript find index 
Javascript :: javascript create an array 
Javascript :: Vue JS Production mode refresh causing 404 error 
Javascript :: Math.avg 
Javascript :: get current location city name react native 
Javascript :: js convert array to object 
Javascript :: global variable vuejs 
Javascript :: fs flies in dir 
Javascript :: express.js hello world 
Javascript :: limit data with axios in react js 
Javascript :: array map 
Javascript :: js sleep 1 sec 
Javascript :: react POST ERROR HANDLING 
Javascript :: Find Smallest Number by function in Javascript 
Javascript :: javascript add update query parameter to url 
Javascript :: javascript wrap object in array 
Javascript :: lodash find all in array 
Javascript :: window location any web 
Javascript :: how to read files in node 
Javascript :: trim text after a certain word in js 
Javascript :: lodash find array of strings 
Javascript :: break statement in javascript 
Javascript :: for in js 
Javascript :: appendchild on specific position 
Javascript :: Make Floating label TextInput in react native 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =