Last active
September 18, 2015 07:57
-
-
Save mort3za/28713c3dd2b19df843cd to your computer and use it in GitHub Desktop.
A safe path generator from a string (item title) that wont break your router, using regex. In Javascript.
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
var pathGen = function(title){ | |
// replaces all special characters and white spaces with DASH. | |
var path = title.replace( /([\s`~!@#$%^&*()_|+=?;:'",.<>\{\}\[\]\\\/])/gi, "-"); | |
path = path.replace(/([-]{2,})/gi, '-'); | |
return path; | |
}; | |
// source: http://stackoverflow.com/a/11090301/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment