Last active
March 14, 2019 12:56
-
-
Save denneulin/56926e02c230c5ca17c56630148f26f8 to your computer and use it in GitHub Desktop.
Tips
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 _ = require('lodash'); | |
const str = '1dé@#j. à$42^ù`=:/+%M£¨-)àç!Їжакè§("^é& vu'; | |
// exclude all special characters and spaces in a string | |
const result = _.deburr(str).replace(/\W/g, ''); | |
// result = 1deja42uMaceevu | |
// exclude all special characters and replaces spaces by underscore in a string | |
// N spaces side by side = 1 underscore | |
const result = _.deburr(str).replace(/[^\w\s]/g, '').trim().replace(/\s+/g, '_'); | |
// result = 1dej_a42uMacee_vu |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment