Skip to content

Instantly share code, notes, and snippets.

@denneulin
Last active March 14, 2019 12:56
Show Gist options
  • Save denneulin/56926e02c230c5ca17c56630148f26f8 to your computer and use it in GitHub Desktop.
Save denneulin/56926e02c230c5ca17c56630148f26f8 to your computer and use it in GitHub Desktop.
Tips
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