DEV Community

Discussion on: Daily Challenge #179 - Hide Phone Numbers

Collapse
 
mellen profile image
Matt Ellen • Edited

ONE REGEX TO RULE THEM

Put your separators where you want! I'll find them all.

const encryptNum = num => num.replace(/((\d[-\s.]?){4})(\d)([\s.-]?)(\d)([\s.-]?)(\d)([\s.-]?)(\d)([\s.-]?)(\d)([\s.-]?)(\d)/, '$1X$4X$6X$8X$10X$12X');