Skip to content

Instantly share code, notes, and snippets.

View eduardorangell's full-sized avatar
🍺
Earned: Hangover

Eduardo Rangell eduardorangell

🍺
Earned: Hangover
View GitHub Profile
@eduardorangell
eduardorangell / cpf.js
Created April 4, 2022 21:51
Regex para formatar CPF
const cpf = "1234567890";
console.log(cpf.replace(/(\d{3})(\d{3})(\d{3})(\d{2})/, '$1.$2.$3-$4'));
@eduardorangell
eduardorangell / replacespecialchars.js
Created June 14, 2021 21:56
Replacing Special Characters in JavaScript
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!!!'));