Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I put an escape character (NOT "escaped" character) in a Ruby regex?

Tags:

regex

ruby

I'm trying to parse a text file that has ANSI color sequences in it, e.g.

\e[0;37m

How can I build a regex to match this in Ruby?

like image 528
Amy Avatar asked Nov 05 '22 15:11

Amy


1 Answers

It turns out this works absolutely fine:

def strip_ansi_sequence (str)
  str.gsub(/\e\[[^m]*m/, '')
end
like image 85
Amy Avatar answered Nov 10 '22 00:11

Amy