http://qs1969.pair.com?node_id=326162


in reply to This looks like someone sneezed and hit the keyboard

this is expecting to parse a command line prompt which uses ANSI escapes:
ANSI Color Codes in brief: 0 to restore default color 1 for brighter colors 4 for underlined text 5 for flashing text 30 for black foreground 31 for red foreground 32 for green foreground 33 for yellow (or brown) foreground 34 for blue foreground 35 for purple foreground 36 for cyan foreground 37 for white (or gray) foreground 40 for black background 41 for red background 42 for green background 43 for yellow (or brown) background 44 for blue background 45 for purple background 46 for cyan background 47 for white (or gray) background you use the above codes together with an escape sequence like this (re +place the '#' with the colour code of your choice) : \e[#m Once you've used an escape all subsequent text will be affected until +you use the reset escape \e[0m so if I want to format a part of a line of text, instead of: print "This boring old line of text was supposed to have red text\n"; do this: print "This new improved, brighter, more interesting line of text has +\e[31mred text\e[0m\n" ; If you want to use two escapes on the same piece of text use one of these ';' : \e[#;#m print "This \e[5m new improved \e[0m, \e[5m brighter \e[0m, more \e[5minteresting \e[0m line of text has \e[31;5mflashing red text\e[0m\n" ;

\e[0m (the reset string) requires escaping in the regex, or at least the '\' and '[' do. In pseudo code the regex would read like this :

match anything (.*) grab the rest up to \e[0m

try running it on the couple of the ANSI formatted strings I gave as examples and you'll see how it's working