pub struct EasyRegex(/* private fields */);
Expand description
Main struct includes methods to be chained together in order to create a regular expression.
Implementations§
Source§impl EasyRegex
impl EasyRegex
Sourcepub fn literal(self, expression: &str, settings: &Settings) -> EasyRegex
pub fn literal(self, expression: &str, settings: &Settings) -> EasyRegex
Creates a literal regular expression.
This method takes an expression (a segment of entire pattern) followed
by a set of settings (Settings
struct) that will be concatenated/inserted to the expression itself,
outputing the previous pattern followed by this prepared regular expression.
§Examples
use easy_regex::{EasyRegex, settings::base::DEFAULT};
let result = EasyRegex::new_section().literal("some expression", &DEFAULT);
assert_eq!("some expression", result.get_regex().unwrap().as_str());
Source§impl EasyRegex
impl EasyRegex
Sourcepub fn group(self, expression: &str, group_sttings: &GroupSettings) -> Self
pub fn group(self, expression: &str, group_sttings: &GroupSettings) -> Self
Creates a group of expressions.
This method takes an expression (a segment of entire pattern) followed
by a set of settings (GroupSettings
struct) that will be concatenated/inserted to the expression itself,
outputing the previous pattern followed by this group.
§Examples
use easy_regex::{EasyRegex, settings::group::OPTIONAL_GROUP};
let result = EasyRegex::new_section().group("expression", &OPTIONAL_GROUP);
assert_eq!("(expression)?", result.get_regex().unwrap().as_str());
Sourcepub fn named_group(
self,
name: &str,
expression: &str,
group_settings: &GroupSettings,
) -> Self
pub fn named_group( self, name: &str, expression: &str, group_settings: &GroupSettings, ) -> Self
Same as the group
method with the option to add a custom name to the group.
§Examples
use easy_regex::{EasyRegex, settings::group::OPTIONAL_GROUP};
let result = EasyRegex::new_section().named_group("my_group", "expression", &OPTIONAL_GROUP);
assert_eq!("(?P<my_group>expression)?", result.get_regex().unwrap().as_str());
Sourcepub fn into_group(self, settings: &Settings) -> Self
pub fn into_group(self, settings: &Settings) -> Self
Turns the previous expressions into a capturing group. It uses Settings
struct for the settings parameter.
§Examples
use easy_regex::{EasyRegex, settings::base::OPTIONAL};
let result = EasyRegex::new(r"\d{3}").into_group(&OPTIONAL);
assert_eq!(r"(\d{3})?", result.get_regex().unwrap().as_str());
Sourcepub fn into_named_group(self, name: &str, settings: &Settings) -> Self
pub fn into_named_group(self, name: &str, settings: &Settings) -> Self
A variation of into_group
having name option (?P<name>RegExp).
Sourcepub fn into_non_capturing(self) -> Self
pub fn into_non_capturing(self) -> Self
A variation of into_group
having non-capturing option (?:RegExp).
Sourcepub fn into_insensitive_group(self) -> Self
pub fn into_insensitive_group(self) -> Self
A variation of into_group
having Insensitive flag (?i).
Sourcepub fn into_multline_group(self) -> Self
pub fn into_multline_group(self) -> Self
A variation of into_group
having Multiline flag (?m).
Sourcepub fn into_dot_match_newline_group(self) -> Self
pub fn into_dot_match_newline_group(self) -> Self
A variation of into_group
having Dot All flag (?s).
Sourcepub fn into_ignore_whitespace_group(self) -> Self
pub fn into_ignore_whitespace_group(self) -> Self
A variation of into_group
ignoring whitespaces (?x).
Sourcepub fn into_insensitive_non_capturing(self) -> Self
pub fn into_insensitive_non_capturing(self) -> Self
A variation of into_non_capturing
having Insensitive flag (?i).
Sourcepub fn into_multiline_non_capturing(self) -> Self
pub fn into_multiline_non_capturing(self) -> Self
A variation of into_non_capturing
having Multiline flag (?m).
Sourcepub fn into_dot_match_newline_non_capturing(self) -> Self
pub fn into_dot_match_newline_non_capturing(self) -> Self
A variation of into_non_capturing
having Dot All flag (?s).
Sourcepub fn into_ignore_whitespace_non_capturing(self) -> Self
pub fn into_ignore_whitespace_non_capturing(self) -> Self
A variation of into_non_capturing
ignoring whitespaces (?x).
Sourcepub fn into_sensitive_group(self) -> Self
pub fn into_sensitive_group(self) -> Self
A variation of into_group
having Insensitive flag cleared (?-i).
Sourcepub fn into_single_line_group(self) -> Self
pub fn into_single_line_group(self) -> Self
A variation of into_group
having Multiline flag cleared (?-m).
Sourcepub fn into_dot_dismatch_newline_group(self) -> Self
pub fn into_dot_dismatch_newline_group(self) -> Self
A variation of into_group
having Dot All flag cleared (?-s).
Sourcepub fn into_include_whitespace_group(self) -> Self
pub fn into_include_whitespace_group(self) -> Self
A variation of into_group
taking whitespaces into account (?-x).
Sourcepub fn into_sensitive_non_capturing(self) -> Self
pub fn into_sensitive_non_capturing(self) -> Self
A variation of into_non_capturing
having Insensitive flag cleared (?-i).
Sourcepub fn into_single_line_non_capturing(self) -> Self
pub fn into_single_line_non_capturing(self) -> Self
A variation of into_non_capturing
having Multiline flag cleared (?-m).
Sourcepub fn into_dot_dismatch_newline_non_capturing(self) -> Self
pub fn into_dot_dismatch_newline_non_capturing(self) -> Self
A variation of into_non_capturing
having Dot All flag cleared (?-s).
Sourcepub fn into_include_whitespace_non_capturing(self) -> Self
pub fn into_include_whitespace_non_capturing(self) -> Self
A variation of into_non_capturing
taking whitespaces into account (?-x).
Source§impl EasyRegex
impl EasyRegex
Sourcepub fn list(self, expression: &str, settings: &Settings) -> EasyRegex
pub fn list(self, expression: &str, settings: &Settings) -> EasyRegex
Creates a list of expressions.
This method takes an expression (a segment of entire pattern) followed
by a set of settings (Settings
struct) that will be concatenated/inserted to the expression itself,
outputing the previous pattern followed by this list.
§Examples
use easy_regex::{EasyRegex, settings::base::DEFAULT};
let result = EasyRegex::new_section().list("some_list", &DEFAULT);
assert_eq!("[some_list]", result.get_regex().unwrap().as_str());
Sourcepub fn into_list(self, settings: &Settings) -> EasyRegex
pub fn into_list(self, settings: &Settings) -> EasyRegex
Turns the previous expressions into a list.
§Examples
use easy_regex::{EasyRegex, settings::base::OPTIONAL_UNGREEDY};
let result = EasyRegex::new(r"a-z").into_list(&OPTIONAL_UNGREEDY);
assert_eq!(r"[a-z]??", result.get_regex().unwrap().as_str());
Source§impl EasyRegex
impl EasyRegex
Sourcepub fn start_of_line() -> Self
pub fn start_of_line() -> Self
Creates an EasyRegex
instance starting with the ^
character, asserts position at start of the string.
Sourcepub fn not(self, expression: &str) -> Self
pub fn not(self, expression: &str) -> Self
Creates a list having ^
at the beginning.
§Examples
use easy_regex::EasyRegex;
let result = EasyRegex::new_section().not("abc");
assert_eq!("[^abc]", result.get_regex().unwrap().as_str());
Sourcepub fn literal_space(self) -> Self
pub fn literal_space(self) -> Self
Adds one space character i.e. “ “ to the previous expression.
Sourcepub fn end_of_line(self) -> Self
pub fn end_of_line(self) -> Self
Adds the ending pattern $
, asserts position at the end of the string.
Sourcepub fn insensitive() -> Self
pub fn insensitive() -> Self
Creates an EasyRegex
instance starting with the (?i)
flag.
Sourcepub fn dot_match_newline() -> Self
pub fn dot_match_newline() -> Self
Creates an EasyRegex
instance starting with the (?s)
flag.
Sourcepub fn ignore_whitespace() -> Self
pub fn ignore_whitespace() -> Self
Creates an EasyRegex
instance starting with the (?x)
flag.
Source§impl EasyRegex
impl EasyRegex
Sourcepub fn only_the_beginning() -> Self
pub fn only_the_beginning() -> Self
Creates an EasyRegex
instance starting with the \A
character, asserts position at start of the string.
Sourcepub fn word_boundary(self) -> Self
pub fn word_boundary(self) -> Self
Adds the \b
metacharacter, asserts position at a word boundary.
Sourcepub fn word(self, settings: &Settings) -> Self
pub fn word(self, settings: &Settings) -> Self
Adds the \w
metacharacter, matches any word character [a-zA-Z0-9_].
Sourcepub fn non_word(self, settings: &Settings) -> Self
pub fn non_word(self, settings: &Settings) -> Self
Adds the \w
metacharacter, matches any non-word character [^a-zA-Z0-9_].
Sourcepub fn digit(self, settings: &Settings) -> Self
pub fn digit(self, settings: &Settings) -> Self
Adds the \d
metacharacter, matches digit character [0-9].
Sourcepub fn non_digit(self, settings: &Settings) -> Self
pub fn non_digit(self, settings: &Settings) -> Self
Adds the \D
metacharacter, matches any non-digit character [^0-9].
Sourcepub fn whitespace(self, settings: &Settings) -> Self
pub fn whitespace(self, settings: &Settings) -> Self
Adds the \s
metacharacter, matches any whitespace character [\r\n\t\f\v ].
Sourcepub fn non_whitespace(self, settings: &Settings) -> Self
pub fn non_whitespace(self, settings: &Settings) -> Self
Adds the \S
metacharacter, matches any non-whitespace character [^\r\n\t\f\v ].
Sourcepub fn non_word_boundary(self) -> Self
pub fn non_word_boundary(self) -> Self
Adds the \B
metacharacter, asserts position anywhere but NOT at a word boundary.
Sourcepub fn only_the_end(self) -> Self
pub fn only_the_end(self) -> Self
Adds the ending metacharacter \z
, asserts position at the end of the text.
Source§impl EasyRegex
impl EasyRegex
Sourcepub fn new_section() -> Self
pub fn new_section() -> Self
Creates an empty EasyRegex
instance, useful for start of a pattern.