Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUST

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.
 
PREVIOUS NEXT
Tagged: #rust #regex #statement
ADD COMMENT
Topic
Name
4+1 =