Search code examples
lualua-patterns

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?


Solution

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

    Thanks to Egor Skriptunoff!