Real ANSI colour codes look like ESC[<number>m where ESC is the character 27, and can be matched using \e in a perl regular expression. The number denotes the colour, possible codes are:
// common defines #define NORMAL "\e[0m" #define BOLD "\e[1m" #define UNDERSCORE "\e[4m" #define BLINK "\e[5m" #define INVERSE "\e[7m" // foreground colours #define ANSI_BLACK "\e[30m" #define ANSI_RED "\e[31m" #define ANSI_GREEN "\e[32m" #define ANSI_YELLOW "\e[33m" #define ANSI_BLUE "\e[34m" #define ANSI_PURPLE "\e[35m" #define ANSI_CYAN "\e[36m" #define ANSI_WHITE "\e[37m" // background colours #define ANSI_BACK_BLACK "\e[40m" #define ANSI_BACK_RED "\e[41m" #define ANSI_BACK_GREEN "\e[42m" #define ANSI_BACK_YELLOW "\e[43m" #define ANSI_BACK_BLUE "\e[44m" #define ANSI_BACK_PURPLE "\e[45m" #define ANSI_BACK_CYAN "\e[46m" #define ANSI_BACK_WHITE "\e[47m"
(Yup, I grabbed that from a mud)
So to match ANSI colours you need:
$line =~ s/\e\[\d+m//g;
To see the colour codes, at least in unix/linux, just show the file with 'less'. That makes them show up as ESC[1mESC[31m here.

If that doesn't help, you'll need to show an example somehow.

C.


In reply to Re: Removing ANSI Color Codes by castaway
in thread Removing ANSI Color Codes by narse

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.