Search
 
SCRIPT & CODE EXAMPLE
 

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.
Comment

PREVIOUS NEXT
Code Example
Rust :: armanriazi•rust•clone•vs•copy 
Rust :: armanriazi•rust•unsafe•comparison•references•smartpointers•rawpointer 
Rust :: rust missing lifetime specifier 
Rust :: armanriazi•rust•mem•leak 
Rust :: armanriazi•rust•error•E0502•cannot borrow `s` as mutable because it is also borrowed as immutable 
Rust :: rust create hashmap from delimited data in string 
Rust :: rust•armanriazi•static•str 
Rust :: rust•armanriazi•error•cannot be formatted with the default formatter 
Rust :: armanriazi•rust•rc•vs•refcell 
Rust :: how to get public addres from private key solana cli 
Rust :: rust•armanriazi•trait•PartialEq 
Rust :: rust•armanriazi•generic 
Rust :: rust empty vector 
Lua :: How to make an NPC chat in roblox 
Lua :: luau make region3 
Lua :: luau make debounce 
Lua :: roblox lua gui drag 
Lua :: roblox vector3 
Lua :: wait() in lua 
Lua :: replace part of string lua 
Lua :: roblox text color 
Lua :: lua empty table 
Lua :: lua unpack 5.4 
Lua :: lua pairs 
Lua :: lua to float 
Matlab :: to detect if a data frame has nan values 
Matlab :: matlab label size 
Matlab :: matlab new line in string 
Basic :: split to list vb.net 
Elixir :: elixir datetime to timestamp 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =