How to search a word in a string with regular expression (RegExp) in Node.js

2 Answers

0 votes
const str = "Node.js is a JavaScript runtime built on Google V8 JavaScript engine";
  
const index = str.search(/built/i)
 
console.log(index); 
 
 
 
       
/*
run:
       
32
       
*/

 



answered May 28, 2022 by avibootz
0 votes
const str = "Node.js is a JavaScript runtime BUILT on Google V8 JavaScript engine";
  
const index = str.search(/built/i) // i - modifier for search case-insensitive
 
console.log(index); 
 
 
 
       
/*
run:
       
32
       
*/

 



answered May 28, 2022 by avibootz
...