expression

Regex::is_match: existence test

Use a Boolean search when only presence matters. The pattern can match anywhere unless constrained by anchors. This example uses the external regex crate; see the staged Cargo manifest. Expected stdout (not executed): true false Common mistake: Assuming a successful search validates the entire input.

Formal Syntax & Structure

rust syntaxrust
re.is_match(text) -> bool

Working Example

Example Snippetrust
fn main() {    let re = regex::Regex::new(r"cat").unwrap();    println!("{} {}", re.is_match("a cat sleeps"), re.is_match("dog"));}
Rust Reference