How to use regex crate in Rust regular expressions

Add the regex crate to Cargo.toml, compile patterns with Regex::new, and use replace_all or is_match to process strings.

Add the regex crate to your dependencies and use Regex::new to compile patterns, then call .replace_all or .is_match on your strings.

use regex::Regex;

let re = Regex::new(r"(?m)^ >").unwrap();
let fixed = re.replace_all(&input, ">");

For workspace projects like the Rust Book tools, define regex = "1.3.3" in [workspace.dependencies] and reference it with regex = { workspace = true } in your package's [dependencies].