Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

IRC color code stripping

by Shadow1 (Initiate)
on Sep 23, 2006 at 12:32 UTC ( [id://574508]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://574508]
Approved by Corion
Front-paged by diotalevi
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2025-06-17 07:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.