How to search a word in a string with regular expression (RegExp) in TypeScript

2 Answers

0 votes
const str : string = "typescript strongly typed programming language";
  
const index = str.search(/typed/i);
 
console.log(index); 
 
 
 
       
/*
run:
       
20
       
*/

 



answered May 28, 2022 by avibootz
0 votes
const str : string = "typescript strongly TYPED programming language";
  
const index = str.search(/typed/i) // i - modifier for search case-insensitive
 
console.log(index); 
 
 
 
       
/*
run:
       
20
       
*/

 



answered May 28, 2022 by avibootz
...