Back to all patterns
ANSI Escape Sequence (Terminal Control)
Extraction
Matches an ANSI escape sequence (e.g., color codes, cursor movement).
/\x1b\[[0-9;?]*[A-Za-z]/How it works
Useful for stripping ANSI codes from log files before searching. Form: ESC, [, parameter bytes (digits, ;, ?), terminator letter.
Test Cases
Should Match
- [31m
- [2J
- [?25h
Should NOT Match
- [31m
- \x1b31m
- plain text
Quick Summary
Matches an ANSI escape sequence for terminal styling and cursor control.
Use Cases
When to use it
- Stripping ANSI codes from logs before grep or storage
- Counting visible vs raw characters when terminal output is captured to a file
- Sanitizing terminal output displayed in a web UI