// 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)^([0-9]{3})-?([0-9]{3})-?([0-9]{3})-?([0-9]{3})?$").unwrap();
let string = "009026405
01009556500
226-356-839
00829029200
008-018-454
009-513-213
00383951900
000147765000
96029000672
008-743-791
009568337
136759989000
009724967000
2RC0001624466
286169755000
201-947-430-0
241402504000
223651060000
";
let substitution = "[$1.$2.$3.${4:+$4:000}]";
// 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/