regex_ansi 0.1.0

ANSI escape sequence regular expression (Rust port of ansi-regex behavior)
Documentation
  • Coverage
  • 80%
    4 out of 5 items documented0 out of 3 items with examples
  • Size
  • Source code size: 36.84 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.37 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • MuntasirSZN/regex_ansi
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • MuntasirSZN

regex_ansi

High‑fidelity Rust port of the popular JavaScript ansi-regex pattern. Supplies a battle‑tested regular expression that matches ANSI escape sequences (CSI, OSC, etc.).

Example

use regex_ansi::ansi_regex;

fn main() {
    let text = "\x1b[31mError:\x1b[0m something failed";
    let cleaned = ansi_regex().replace_all(text, "");
    assert_eq!(cleaned, "Error: something failed");
}

Features

  • Constant, pre‑audited pattern identical in semantics to ansi-regex@6 (JS).
  • Two ready regex constructors: global style (ansi_regex) and first match style (ansi_regex_first).
  • No unsafe code.

API

  • pub fn ansi_regex() -> &'static regex::Regex
  • pub fn ansi_regex_first() -> &'static regex::Regex
  • pub fn pattern() -> &'static str – raw pattern string.

Performance Notes

  • The OSC portion is implemented using a negated character class for linear behavior.

License

Licensed under MIT. Derivative work conceptually based on the pattern logic from the original JavaScript project.