Skip to content

Latest commit

 

History

History
25 lines (16 loc) · 954 Bytes

how-to-ignore-case-in-rust-regex.md

File metadata and controls

25 lines (16 loc) · 954 Bytes

How to ignore case in Rust regex?

// plain

To ignore case in Rust regex, you can use the i flag. This flag will cause the regex to ignore case when matching. For example:

let re = Regex::new(r"(?i)hello").unwrap();
assert!(re.is_match("HELLO"));

The code above creates a regex with the i flag, which causes the regex to ignore case when matching. The assert! statement then checks that the regex matches the string HELLO, which it does.

The parts of the code are:

  • Regex::new(r"(?i)hello"): This creates a new regex with the i flag, which causes the regex to ignore case when matching.
  • assert!(re.is_match("HELLO")): This checks that the regex matches the string HELLO, which it does.

Helpful links

group: rust-regex

onelinerhub: How to ignore case in Rust regex?