Skip to content

Full string match #737

Answered by BurntSushi
XakepSDK asked this question in Q&A
Jan 6, 2021 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

From the docs:

All searching is done with an implicit .*? at the beginning and end of an expression. To force an expression to match the whole string (or a prefix or a suffix), you must use an anchor like ^ or $ (or \A and \z).

So in your case, you would want:

use regex::Regex;

fn main() {
    let matched = Regex::new(r"^regexStr$").unwrap().is_match("string");
    println!("{:?}", matched);
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@XakepSDK
Comment options

@BurntSushi
Comment options

Answer selected by XakepSDK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants