开发者

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

开发者 https://www.devze.com 2022-12-23 01:10 出处:网络
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?It turns out this works absolutely fine:

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?


It turns out this works absolutely fine:

def strip_ansi_sequence (str)
  str.gsub(/\e\[[^m]*m/, '')
end
0

精彩评论

暂无评论...
验证码 换一张
取 消