How do I do a regex string substitution using a Regex with backreferences in Rust?

Viewed 1246

I'm trying the following code, but, which works for other languages, but not for Rust

#[test]
fn regex_test() {
    let regex = Regex::new(r"(\*|_)(.*?)\1").unwrap();
    let string = "*quack* klfjalksd *this* is a *test* **dfadfjkl** ";
    let substitution = "<em>$2</em>";

    // result will be a String with the substituted value
    let result = regex.replace_all(string, substitution);

    println!("{}", result);

}

The result has none of the substitutions:

*quack* klfjalksd *this* is a *test* **dfadfjkl** 
1 Answers
Related