Module: BB::String

Defined in:
lib/blackbox/string.rb

Overview

String utilities.

Class Method Summary collapse

Class Method Details

.strip_ansi(text) ⇒ String

Strip ANSI escape sequences from String.

Parameters:

  • text (String)

    Input string (dirty)

Returns:

  • (String)

    Output string (cleaned)



10
11
12
13
14
# File 'lib/blackbox/string.rb', line 10

def strip_ansi(text)
  text.gsub(/\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]/, '')
      .gsub(/\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]/, '')
      .gsub(/(\x03|\x1a)/, '')
end