How to check if a string ends with 2 letters followed by a digit in TypeScript

1 Answer

0 votes
const str = "typescript php cpp8";
  
const regex = /([a-zA-Z]{2}[0-9])$/;

const result = str.match(regex);

console.log(result ? result[0] : null);

 
// [a-zA-Z] letters {2} repeated 2 times [0-9] followed by digit $ at end of string
  
  
  
/*
  
run:
  
"pp8"
  
*/

 



answered Jun 7, 2022 by avibootz
...