Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua: ANSI escapes pattern

I'm writing logging library for Lua, which actually is something like rewrite & bundle of some npm modules (like log-update, chalk, etc.). I want to get true width of string, so I need to strip ANSI escape codes from it. I found npm module that provides regexp for it. But I don't understand how to match these characters in Lua via Lua patterns. Can you help me to write pattern, which does it?

like image 552
Malyutin Egor Avatar asked Jun 25 '26 15:06

Malyutin Egor


1 Answers

text = string.gsub(text, "[\27\155][][()#;?%d]*[A-PRZcf-ntqry=><~]", "")

Thanks to Egor Skriptunoff!

like image 94
Malyutin Egor Avatar answered Jun 28 '26 02:06

Malyutin Egor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!