Skip to content

Instantly share code, notes, and snippets.

@omniosi
Last active November 28, 2017 22:06
Show Gist options
  • Save omniosi/74f9df211284755914a76db6f7cc2bba to your computer and use it in GitHub Desktop.
Save omniosi/74f9df211284755914a76db6f7cc2bba to your computer and use it in GitHub Desktop.
replace URL illegal characters with hyphen using RegEx
" 0123456789 _+-.,!@#$%^&*();\/|<>"'~`?=:".replace(/[\/\s&!@#$%^*(){}[\];\\|<>"'?,.~`+=:]/g,'-')
// http://regexr.com/3h9d0
/* To quote section 2.3 of RFC 3986:
"Characters that are allowed in a URI but do not have a reserved purpose are called unreserved. These include uppercase and lowercase letters, decimal digits, hyphen, period, underscore, and tilde."
ALPHA DIGIT "-" / "." / "_" / "~"
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment