最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Regular expression remove the special character from a file name for Windows - Stack Overflow

programmeradmin4浏览0评论

From (v=vs.85).aspx, We know Windows reserve some characters:

< (less than)
> (greater than)
: (colon)
" (double quote)
/ (forward slash)
\ (backslash)
| (vertical bar or pipe)
? (question mark)
* (asterisk)

I have a file name which contains e of those special characters, I want to replace those with "", something like this (string.replace(/\<>/g, '')
Thanks

From http://msdn.microsoft./en-us/library/windows/desktop/aa365247(v=vs.85).aspx, We know Windows reserve some characters:

< (less than)
> (greater than)
: (colon)
" (double quote)
/ (forward slash)
\ (backslash)
| (vertical bar or pipe)
? (question mark)
* (asterisk)

I have a file name which contains e of those special characters, I want to replace those with "", something like this (string.replace(/\<>/g, '')
Thanks

Share Improve this question asked Aug 8, 2014 at 17:35 yongnanyongnan 4157 silver badges20 bronze badges 2
  • This is a challenging request as Windows has odd file name rules. See this SO article: stackoverflow./questions/754307/… – jwatts1980 Commented Aug 8, 2014 at 17:39
  • thanks, I didn't find it when I google it. Sorry for ask dumplicate question – yongnan Commented Aug 8, 2014 at 17:44
Add a ment  | 

1 Answer 1

Reset to default 8

You can put all those characters inside a character set:

string.replace( /[<>:"\/\\|?*]+/g, '' );
发布评论

评论列表(0)

  1. 暂无评论