expression

NoExpand: literal replacement

Use NoExpand when replacement content must be copied literally, even if it contains dollar signs. This example uses the external regex crate; see the staged Cargo manifest. Expected stdout (not executed): $5 $5 Common mistake: Passing literal external text as a capture-expanding template.

Formal Syntax & Structure

rust syntaxrust
regex::NoExpand(text)

Working Example

Example Snippetrust
fn main() {    let re = regex::Regex::new("TOKEN").unwrap();    println!("{}", re.replace_all("TOKEN TOKEN", regex::NoExpand("$5")));}
Rust Reference