human_regex/
flags.rs

1//! Functions for adding flags
2// i     case-insensitive: letters match both upper and lower case
3// m     multi-line mode: ^ and $ match begin/end of line
4// s     allow . to match \n
5// u     Unicode support (enabled by default)
6
7use super::humanregex::HumanRegex;
8
9/// Makes all matches case insensitive, matching both upper and lowercase letters.
10/// ```
11/// use human_regex::{case_insensitive, text};
12/// let regex_string = case_insensitive(text("spongebob"));
13/// assert!(regex_string.to_regex().is_match("SpOnGeBoB"));
14/// assert!(regex_string.to_regex().is_match("spongebob"));
15/// assert!(!regex_string.to_regex().is_match("PaTrIcK"));
16/// ```
17pub fn case_insensitive(target: HumanRegex) -> HumanRegex {
18    HumanRegex(format!("(?i:{})", target))
19}
20
21/// Enables multiline mode, which will allow `beginning()` and `end()` to match the beginning and end of lines
22pub fn multi_line_mode(target: HumanRegex) -> HumanRegex {
23    HumanRegex(format!("(?m:{})", target))
24}
25
26/// A function that will allow `.` to match newlines (`\n`)
27pub fn dot_matches_newline_too(target: HumanRegex) -> HumanRegex {
28    HumanRegex(format!("(?s:{})", target))
29}
30
31/// A function to disable unicode support
32pub fn disable_unicode(target: HumanRegex) -> HumanRegex {
33    HumanRegex(format!("(?-u:{})", target))
34}