1
1

More than 3 years have passed since last update.

js 3連続以上の改行を2行の改行に変換する

Posted at

Twitterとかでありますよね。
連続した改行を入力しても、改行幅はマックス2行までに制限されるやつ。
ああいうやつをjsでサッと実装したいときはこれでおk

let newValue = value.replace(/(\r\n){3,}|\r{3,}|\n{3,}/, '\n\n');

参考 013:正規表現を使い、連続した改行コード・改行文字を取り除く

1
1
1

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