Showing entries with tag "ANSI".

Found 2 entries

Perl: regular expression to check for ANSI sequences
I needed to test if a given string contains ANSI color codes. Here is the regexp I settled on to check for that: ```perl my $ansi_color_regex = qr/\e\[[0-9]{1,3}(?:;[0-9]{1,3}){0,3}[mK]/; if ($str =~ /$ansi_color_regex/) { print "String has some ANSI in it\n"; } ``` Alternately you can *capture* the color numbers with this regex: ```perl my $ansi_color_regex = qr/(\e\[([0-9]{1,3}(;[0-9]{1,3}){0,3})[mK])/; ```
Perl: ANSI colors
Perl's `Term::ANSIColor` is good but sometime it's overkill. I wrote a function to change colors before your print. ```perl $color = color("13_on_5"); $reset = color("reset"); print $color . "Pink on purple" . $reset . "\n"; ``` ```perl # String format:...