Stripping color codes in irssi scripts

So you're writing an IRC script for irssi and you want to strip formatting codes (including colors, bold, underline, etc) from some variable. This is possible with s///, and google will show many (usually not very readable) examples.

But there's an easier way: irssi has an undocumented function called Irssi::strip_codes that does all the work for you. And since irssi exports all functions into your script's namespace unconditionally, you don't even need to type the Irssi:: part:

my $clean = strip_codes($dirrrty);

This will remove so-called “mIRC colors”, irssi's internal formatting codes, and ANSI color sequences.

Leave a comment

About mauke

user-pic I blog about Perl.