Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression remove the special character from a file name for Windows

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

like image 966
yongnan Avatar asked Aug 08 '14 17:08

yongnan


People also ask

What special characters are allowed in Windows file names?

In both NTFS and FAT file systems, the special file name characters are: '\', '/', '. ', '?' , and '*'. On OEM code pages, these special characters are in the ASCII range of characters (0x00 through 0x7F).


1 Answers

You can put all those characters inside a character set:

string.replace( /[<>:"\/\\|?*]+/g, '' );
like image 128
hjpotter92 Avatar answered Oct 06 '22 00:10

hjpotter92