expression

Multiline anchors

Multiline mode allows line anchors to match at line boundaries. The absolute anchors remain suitable for whole-input checks. This example uses the external regex crate; see the staged Cargo manifest. Expected stdout (not executed): true false Common mistake: Confusing a line match with a whole-document match.

Formal Syntax & Structure

rust syntaxrust
(?m)^pattern$

Working Example

Example Snippetrust
fn main() {    let re = regex::Regex::new(r"(?m)^ok$").unwrap();    let text = "start\nok\nend";    println!("{} {}", re.is_match(text), regex::Regex::new(r"\Aok\z").unwrap().is_match(text));}
Rust Reference