Shadow1 has asked for the wisdom of the Perl Monks concerning the following question:

Hey all! I'm writing a script to work with an IRC channel, but the channel has color codes. In order to properly parse the messages, I need to somehow remove the color codes, but most of the regexes I've written don't work. Is there a regex that would allow me to remove all of the codes at once, or do I need to work around it? Thanks.

Replies are listed 'Best First'.
Re: IRC color code stripping
by hgolden (Pilgrim) on Sep 23, 2006 at 13:36 UTC
    Hey

    Since I've learned my lesson about parsing without a parser, allow me to point you to Parse::IRC, which could be a lot of help to you. Enjoy!

    Hays

Re: IRC color code stripping
by liverpole (Monsignor) on Sep 23, 2006 at 12:41 UTC
    Hi Shadow1,

    It will help you immensely if you can provide some examples of the messages you're trying to parse.  Without that, you'll get a lot fewer responses, and only then from people who happen to know what the output from an IRC channel looks like.

    Needless to say, if you can provide some of the code that you've written (even if it isn't yet quite working), it will also help a great deal towards given you a quicker/better answer, since it will provide a context.


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
Re: IRC color code stripping
by ambrus (Abbot) on Sep 23, 2006 at 16:04 UTC

    Try something like this (untested): s/\cK\d{1,2}(?:,\d{1,2})?|[\cK\cB\cI\cU\cR\cO]//g

    Update: ikegami is right indeed. Try this then: s/\cC\d{1,2}(?:,\d{1,2})?|[\cC\cB\cI\cU\cR\cO]//g

      \cK should be \cC (at least for mIRC and ircle). Ctrl-K is the shortcut key used to insert colour, but Ctrl-C is the code that is actually inserted.