regex_ansi

Crates.ioregex_ansi
lib.rsregex_ansi
version0.1.0
created_at2025-09-09 15:24:46.201261+00
updated_at2025-09-09 15:24:46.201261+00
descriptionANSI escape sequence regular expression (Rust port of ansi-regex behavior)
homepage
repositoryhttps://github.com/MuntasirSZN/regex_ansi
max_upload_size
id1831064
size37,347
Muntasir Mahmud (MuntasirSZN)

documentation

README

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.

Commit count: 3

cargo fmt