strip_ansi_escapes function in APL to remove ANSI escape sequences from strings. ANSI escape codes are special character sequences used in terminal output to control text formatting, colors, and cursor positioning. When analyzing logs or terminal output, these codes can interfere with text processing, search operations, and data analysis.
You use strip_ansi_escapes when you need to clean up terminal output, colorized logs, or any text that contains ANSI formatting codes. This is particularly useful when ingesting logs from command-line tools, CI/CD pipelines, container logs, or any system that outputs colored or formatted terminal text.
For users of other query languages
If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.Splunk SPL users
Splunk SPL users
In Splunk SPL, you typically use regex-based replacements to remove ANSI escape sequences. APL’s
strip_ansi_escapes provides a dedicated function that handles all standard ANSI escape sequence patterns automatically.ANSI SQL users
ANSI SQL users
ANSI SQL doesn’t have a built-in function for removing ANSI escape sequences. You need to use regex replacement functions specific to your SQL dialect. APL’s
strip_ansi_escapes provides a cross-platform solution that handles various ANSI escape patterns.Usage
Syntax
Parameters
| Name | Type | Description |
|---|---|---|
text | string | The string containing ANSI escape sequences that you want to remove. |
Returns
A string with all ANSI escape sequences removed, leaving only the plain text content.List of related functions
- trim: Use
trimto remove leading and trailing characters. Usestrip_ansi_escapesspecifically for removing ANSI escape sequences anywhere in the string. - replace_regex: Use
replace_regexfor custom pattern-based replacements. Usestrip_ansi_escapesas a specialized, optimized solution for ANSI codes. - trim_space: Use
trim_spaceto remove whitespace. Usestrip_ansi_escapesto clean formatting codes. - extract: Use
extractto pull specific patterns from text. Usestrip_ansi_escapesto clean the text before extraction for better pattern matching.