0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScript で改行コードを含むすべての文字にマッチさせる

Last updated at Posted at 2017-07-29

改行コードを含むすべての文字にマッチさせたい場合、
単純に[\s\S]で出来ます。
JavaScriptでは、[^]でも同じことが出来ます。

string = "1234\nabcd\n \f\n\r\t\v\n";
result = string.replace(/./g, ".");
console.log(`1\n${result}`);

result = string.replace(/[\s\S]/g, ".");
console.log(`2\n${result}`);

result = string.replace(/[^]/g, ".");
console.log(`3\n${result}`);

出力

1
....
....
..

..
2
.................
3
.................

[^]は、空文字以外とマッチという事なのでしょうか?

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?