Answers for "rust using regex in if statement"

0

rust using regex in if statement

use regex::Regex;

fn are_you_playing_banjo(name: &str) -> String {
   format!("{} {} banjo", name, if Regex::new(r"^[rR]").unwrap().is_match(name) {"plays"} else {"does not play"})
}
// Instead of a normal parameter, the 'if' returns the result of a regex match.
Posted by: Guest on February-20-2021

Browse Popular Code Answers by Language