// 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)(\b(?'first_word'[a-z](?!([[:alnum:]]*_)(?# the word doesn't contain underscores))(?:[a-z0-9]*)))|(\G(?'trailing_word'[A-Z][a-z0-9]*))").unwrap();
let string = "camelCase
camel
camelCaseCase
camel684Case
ca45melCase
camelCase6523Case
camelCaseCaseCaseCaseCase
camelCCase
PascalCase
// some random commentary with Capitalized letters
camel_Snake_Case
";
let substitution = "\\L${first_word}${trailing_word:+_\\L${trailing_word}:}";
// 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/