How to check if a string ends with 2 letters followed by a digit in Node.js

1 Answer

0 votes
const str = "nodejs c++ python1";
  
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:
  
on1
  
*/

 



answered Jun 7, 2022 by avibootz
...