How to strip color codes used by mIRC users?

前端 未结 6 1544
小鲜肉
小鲜肉 2020-12-16 06:15

I\'m writing a IRC bot in Python using irclib and I\'m trying to log the messages on certain channels.
The issue is that some mIRC users and some Bots write using color

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-16 07:06

    As I found this question useful, I figured I'd contribute.

    I added a couple things to the regex

    regex = re.compile("\x1f|\x02|\x03|\x16|\x0f(?:\d{1,2}(?:,\d{1,2})?)?", re.UNICODE)
    

    \x16 removed the "reverse" character. \x0f gets rid of another bold character.

提交回复
热议问题