This regex matches only the most common CSI (Control Sequence Introducer)
sequences that start with ESC[ followed by numeric parameters and
alphabetic final characters.
Matches:
Color codes: \x1b[31m, \x1b[38;5;196m
Cursor movement: \x1b[10;5H, \x1b[2A
Text formatting: \x1b[1m (bold), \x1b[0m (reset)
Does NOT match:
OSC sequences: \x1b]0;title\x07
Complex terminators beyond alphabetic characters
Non-CSI escape sequences
Use cases:
Basic text cleaning for display
Performance-critical applications
Simple terminal output processing
Performance: Fast due to simple pattern
Coverage: ~80-90% of common ANSI sequences
See
COMPLEX_REGEX
Example
constcoloredText = "\x1b[31mError:\x1b[0m Something went wrong"; constcleanText = coloredText.replace(SIMPLE_REGEX, ""); // Result: "Error: Something went wrong"
Simple regular expression for matching basic ANSI escape sequences.
For a more comprehensive regex, see COMPLEX_REGEX.
This regex matches only the most common CSI (Control Sequence Introducer) sequences that start with
ESC[
followed by numeric parameters and alphabetic final characters.Matches:
\x1b[31m
,\x1b[38;5;196m
\x1b[10;5H
,\x1b[2A
\x1b[1m
(bold),\x1b[0m
(reset)Does NOT match:
\x1b]0;title\x07
Use cases:
Performance: Fast due to simple pattern Coverage: ~80-90% of common ANSI sequences