-
-
Save iArnaud/b38f3b8a150102977f789432cc1a7653 to your computer and use it in GitHub Desktop.
Tips
This file contains hidden or 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