1
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 1 year has passed since last update.

#Ruby の #正規表現 で 末尾が数字でない行の改行コードだけを削除する例 ( ruby remove with regexp not newline last of line match )

Last updated at Posted at 2020-04-18
  • ?<! 否定の先読み
  • $ 末尾
  • \\1 キャプチャを置換後に利用
"あいうえお\n123\nABC\n".gsub(/(?<![0-9])$\n/, "")
=> "あいうえお123\nABC"
"XY23\n123\nABC\n12DD\n333".gsub(/(?<![0-9])$\n/, "")
=> "XY23\n123\nABC12DD333"

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

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