9

From http://msdn.microsoft.com/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 come of those special characters, I want to replace those with "", something like this (string.replace(/\<>/g, '')
Thanks

yongnan
  • 405
  • 7
  • 20
  • This is a challenging request as Windows has odd file name rules. See this SO article: http://stackoverflow.com/questions/754307/regex-to-replace-characters-that-windows-doesnt-accept-in-a-filename – jwatts1980 Aug 08 '14 at 17:39
  • thanks, I didn't find it when I google it. Sorry for ask dumplicate question – yongnan Aug 08 '14 at 17:44

1 Answers1

8

You can put all those characters inside a character set:

string.replace( /[<>:"\/\\|?*]+/g, '' );
hjpotter92
  • 78,589
  • 36
  • 144
  • 183
  • I would also add the octothorpe/pound/number symbol # to the regular expression, as this character makes the file unlinkable by some encoders – Aurinxki Mar 08 '22 at 18:33