Trying to replace any non alpha-numeric characters with a hyphen. Can't see why it shouldn't be working. It returns the original string unchanged.
item开发者_StackOverflow社区.mimetype = "image/png";
var mimetype = item.mimetype.toLowerCase().replace("/[^a-z0-9]/g",'-');
Remove the quotes around the regex.
As written, Javascript is looking for the string "/[^a-z0-9]/g"
// This works
"image/png".toLowerCase().replace(/[^a-z0-9]/g,'-');
// And if writing unquoted regular expressions makes you feel icky:
"image/png".toLowerCase().replace(new RegExp("[^a-z0-9]", "g"), '-');
// And if I might do a full rewrite:
"image/png".toLowerCase().replace(/\W/g, '-');
More here
You've put a string instead of a regex. Do this:
.replace(/[^a-z0-9]/g,'-');
精彩评论