Macro lazy_regex_proc_macros::regex_replace

source ยท
regex_replace!() { /* proc-macro */ }
Expand description

Replaces the leftmost match in the second argument using the replacer given as third argument.

When the replacer is a closure, it is given one or more &str, the first one for the whole match and the following ones for the groups. Any optional group with no value is replaced with "".

Example:

let text = "Fuu fuuu";
let text = regex_replace!(
    "f(u*)"i,
    text,
    |_, suffix: &str| format!("F{}", suffix.len()),
);
assert_eq!(text, "F2 fuuu");