Suppose I have a string: phone = '12345678'
I want to extract only the last 4 digits of the string using regex. How to do it?
CodePudding user response:
Use /\d{4}$/
pattern.
JavaScript Example
let phone = '12345678';
console.log(phone.match(/\d{4}$/)[0]); // "5678"