Regex match exact text



examples/regex/regex-simple-match/Cargo.toml
[package]
name = "regex-simple-match"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
regex = "1.9.6"

examples/regex/regex-simple-match/src/main.rs
use regex::Regex;

fn main() {
    let text = "The black cat climbed the green tree";
    println!("{}", text);

    let re = Regex::new(r"cat").unwrap();
    match re.captures(text) {
        Some(value) => println!("Full match: '{}'", &value[0]),
        None => println!("No match"),
    };


    let re = Regex::new(r"dog").unwrap();
    match re.captures(text) {
        Some(value) => println!("Full match: '{}'", &value[0]),
        None => println!("No match"),
    };
}

The black cat climbed the green tree
Full match: 'cat'
No match