13
10

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.

ANSI Escape Sequenceの削除

Posted at

Cucumberの出力するスニペットから、エスケープシーケンスを削除するための、正規表現を書いたのでメモ。

  • Ruby
gsub /\x1B\[[0-9]{1,3}[mK]/, ''
gsub /\e\[\d{1,3}[mK]/, '' #こっちのほうが良さげ
  • Vimでも。
s/\%x1B\[[0-9]\{1,3}[mK]//g
s/\e\[\d\{1,3}[mK]//g
.vimrc
" DeleteAnsiEsc
command! -range=% DeleteAnsiEsc :<line1>,<line2>rubydo gsub /\e\[\d{1,3}[mK]/, ''
nnoremap <Leader>da :<C-u>DeleteAnsiEsc<CR>
vnoremap <Leader>da :DeleteAnsiEsc<CR>

Vimの設定でエスケープシーケンスをyankしないようにできないかなと思ったけど、よくわからなかった。

参照サイト:
ANSI escape code (Wikipedia)
Remove color codes (special characters) with sed
In Vim, how to keep characters concealed even when cursor enters that line (Stack Overflow)

13
10
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
13
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?