home
NOTE: Under Construction - I'm in the middle of upgrading my site and lots of stuff is kinda broken. Please forgive the mess.

Find And Replace In A String With A Regex In Rust

April 2024

This is a basic example of how to use a regular expression to find and replace text in a Rust string.

Code
```cargo
[dependencies]
regex = "1.10.4"
```

use regex::Regex;

fn main() {
  let re = Regex::new(r"brown").unwrap();
  let text = "the quick brown fox".to_string();
  let output = re.replace_all(&text, "red");
  println!("{}", output);
}
Results
the quick red fox
═══ § ═══