javascript - Trying to find the regex for pretty URLs -
i have website structure this:
/docs/one_of_the_resources/one-of-the-resources.html /docs/a_complete_different_resource/a-complete-different-resource.html i want rid of sub-folders in url , this:
/one-of-the-resources.html /a-complete-different-resource.html sub-folders should not affected:
/docs/one_of_the_resources/assets/* the folder name same html file dashes swapped underline , of course there no suffix.
i'm using grunt-contrib-rewrite , grunt-connect.
can't wrap head around it. possible?
you can use negated character class
/\/[^/]+$/ [^/]+matches other/. quantifier+ensures 1 or more characters.$anchors regex @ end of string.
example
string = "/docs/one_of_the_resources/one-of-the-resources.html"; console.log(string.match(/\/[^/]+$/)[0]); // => one-of-the-resources.html
Comments
Post a Comment