LoginSignup
0
0

More than 3 years have passed since last update.

テキストからWindowsのファイル名に使えない記号を置き換えるコード

Last updated at Posted at 2020-08-07

Windowsのファイル名に使えない記号\ / : * ? " < > |を全角記号に置き換えるだけのコードです。
テキストをstrの中に入れてお使い下さい。テンプレートリテラルなので改行ありでも大丈夫です。
そのままブラウザからF12 → consoleに打ち込めば結果が出ます。

コード

var str =
`
text
`;

console.log(
    str.replace(/\\/g, "")
       .replace(/\//g, "")
       .replace(/:/g, "")
       .replace(/\*/g, "")
       .replace(/\?/g, "")
       .replace(/"/g, "")
       .replace(/</g, "")
       .replace(/>/g, "")
       .replace(/\|/g, "")
);
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0