'How to view the literal content of a ZSH string containing colour codes

I'm assuming it's some sort of flag to typeset but I can't for the life of me figure it out.

zsh


Solution 1:[1]

If you know you have valid ANSI color codes and want to get rid of them, this regex will do the trick: \x1b\[[0-?]*[ -/]*m.

With set -o extendedglob:

print -r "${variable//$'\e'\[[0-?]#[ -\/]#m/}"

Perl oneliner:

perl -pe 's/\x1b\[[0-?]*[ -\/]*m//g'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 yut23