This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cpf = "1234567890"; | |
console.log(cpf.replace(/(\d{3})(\d{3})(\d{3})(\d{2})/, '$1.$2.$3-$4')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const replaceSpecialChars = (str) => { | |
return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '') // Remove accents | |
.replace(/([^\w]+|\s+)/g, '-') // Replace space and other characters by hyphen | |
.replace(/\-\-+/g, '-') // Replaces multiple hyphens by one hyphen | |
.replace(/(^-+|-+$)/, ''); // Remove extra hyphens from beginning or end of the string | |
} | |
console.log(replaceSpecialChars('This is a sentence!!!')); |