concept regular expression in category rust

appears as: regular expressions
Rust in Action

This is an excerpt from Manning's book Rust in Action.

To get your feet wet, you’ll be including the regex crate into your program. Crates are the name the Rust community uses where others may use terms such as package, distribution or library. regex will provide you with the ability to match for regular expressions, rather than simply looking for exact matches.

2.11.1. Adding Support for Regular Expressions

Regular expressions add great flexibility to the patterns that we are able to search for.

Listing 2. 26. Searching for patterns with regular expressions (ch2/ch2-with-regex.rs)
use regex::Regex; #1

fn main() {
  let re = Regex::new("picture").unwrap();  #2

  let quote = "Every face, every shop, bedroom window, public-house, and
dark square is a picture feverishly turned--in search of what?
It is the same with books. What do we seek through millions of pages?";

  for line in quote.lines() {
    let contains_substring = re.find(line);
    match contains_substring {  #3
        Some(_) => println!("{}", line),  #4
        None => (),  #5
    }
  }
}