// include the latest version of the regex crate in your Cargo.toml
extern crate regex;
use regex::Regex;
fn main() {
let regex = Regex::new(r"(?m).*?($|\$[sc]\d)").unwrap();
let string = " Есть текст и много строк
В тексте встречаются $s1 $s2 $s3 $s4 $c1 $c2 $c4
В каждой строке есть хоть 1 такой текст, могут быть и 2 и 3 в 1 строке, но без дублей.
Найти я смог их так (\\$s\\d)|(\\$c\\d) и удалить могу их всех, но как удалить все кроме них не понял.
Заранее спасибо за ответ! ";
let substitution = "$1";
// result will be a String with the substituted value
let result = regex.replace_all(string, substitution);
println!("{}", result);
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Rust, please visit: https://docs.rs/regex/latest/regex/