human_regex/
emptymatches.rs

1//! Functions for the empty matches
2
3use super::humanregex::HumanRegex;
4
5/// A function to match a word boundary
6pub fn word_boundary() -> HumanRegex {
7    HumanRegex(r"\b".to_string())
8}
9
10/// A function to match anything BUT a word boundary
11pub fn non_word_boundary() -> HumanRegex {
12    HumanRegex(r"\B".to_string())
13}
14
15/// A function to match the beginning of text (or start-of-line with multi-line mode)
16/// ```
17/// use human_regex::{beginning, text};
18/// let regex_string = beginning() + text("hex");
19/// assert!(regex_string.to_regex().is_match("hexagon"));
20/// assert!(!regex_string.to_regex().is_match("chlorhexadine"));
21/// ```
22pub fn beginning() -> HumanRegex {
23    HumanRegex(r"^".to_string())
24}
25
26/// A function to match the end of text (or end-of-line with multi-line mode)
27/// ```
28/// use human_regex::{end, text};
29/// let regex_string = text("end") + end();
30/// assert!(regex_string.to_regex().is_match("mend"));
31/// assert!(!regex_string.to_regex().is_match("endocrinologist"));
32/// ```
33pub fn end() -> HumanRegex {
34    HumanRegex(r"$".to_string())
35}
36
37/// A function to match the beginning of text (even with multi-line mode enabled)
38/// ```
39/// use human_regex::{beginning_of_text, text};
40/// let regex_string = beginning_of_text() + text("hex");
41/// assert!(regex_string.to_regex().is_match("hexagon"));
42/// assert!(!regex_string.to_regex().is_match("chlorhexadine"));
43/// ```
44pub fn beginning_of_text() -> HumanRegex {
45    HumanRegex(r"\A".to_string())
46}
47
48/// A function to match the end of text (even with multi-line mode enabled)
49/// ```
50/// use human_regex::{end_of_text, text};
51/// let regex_string = text("end") + end_of_text();
52/// assert!(regex_string.to_regex().is_match("mend"));
53/// assert!(!regex_string.to_regex().is_match("endocrinologist"));
54/// ```
55pub fn end_of_text() -> HumanRegex {
56    HumanRegex(r"\z".to_string())
57}