javascript url-safe filename-safe string

前端 未结 4 779
误落风尘
误落风尘 2021-01-30 10:08

Looking for a regex/replace function to take a user inputted string say, \"John Smith\'s Cool Page\" and return a filename/url safe string like \"john_smith_s_cool_page.html\",

4条回答
  •  终归单人心
    2021-01-30 10:42

    I know the original poster asked for a simple Regular Expression, however, there is more involved in sanitizing filenames, including filename length, reserved filenames, and, of course reserved characters.

    Take a look at the code in node-sanitize-filename for a more robust solution.

提交回复
热议问题