Struct EasyRegex

Source
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

Source

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

Source

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());
Source

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());
Source

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());
Source

pub fn into_named_group(self, name: &str, settings: &Settings) -> Self

A variation of into_group having name option (?P<name>RegExp).

Source

pub fn into_non_capturing(self) -> Self

A variation of into_group having non-capturing option (?:RegExp).

Source

pub fn into_insensitive_group(self) -> Self

A variation of into_group having Insensitive flag (?i).

Source

pub fn into_multline_group(self) -> Self

A variation of into_group having Multiline flag (?m).

Source

pub fn into_dot_match_newline_group(self) -> Self

A variation of into_group having Dot All flag (?s).

Source

pub fn into_ignore_whitespace_group(self) -> Self

A variation of into_group ignoring whitespaces (?x).

Source

pub fn into_insensitive_non_capturing(self) -> Self

A variation of into_non_capturing having Insensitive flag (?i).

Source

pub fn into_multiline_non_capturing(self) -> Self

A variation of into_non_capturing having Multiline flag (?m).

Source

pub fn into_dot_match_newline_non_capturing(self) -> Self

A variation of into_non_capturing having Dot All flag (?s).

Source

pub fn into_ignore_whitespace_non_capturing(self) -> Self

A variation of into_non_capturing ignoring whitespaces (?x).

Source

pub fn into_sensitive_group(self) -> Self

A variation of into_group having Insensitive flag cleared (?-i).

Source

pub fn into_single_line_group(self) -> Self

A variation of into_group having Multiline flag cleared (?-m).

Source

pub fn into_dot_dismatch_newline_group(self) -> Self

A variation of into_group having Dot All flag cleared (?-s).

Source

pub fn into_include_whitespace_group(self) -> Self

A variation of into_group taking whitespaces into account (?-x).

Source

pub fn into_sensitive_non_capturing(self) -> Self

A variation of into_non_capturing having Insensitive flag cleared (?-i).

Source

pub fn into_single_line_non_capturing(self) -> Self

A variation of into_non_capturing having Multiline flag cleared (?-m).

Source

pub fn into_dot_dismatch_newline_non_capturing(self) -> Self

A variation of into_non_capturing having Dot All flag cleared (?-s).

Source

pub fn into_include_whitespace_non_capturing(self) -> Self

A variation of into_non_capturing taking whitespaces into account (?-x).

Source§

impl EasyRegex

Source

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());
Source

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

Source

pub fn start_of_line() -> Self

Creates an EasyRegex instance starting with the ^ character, asserts position at start of the string.

Source

pub fn or(self) -> Self

Adds the alternation symbol | to the expression.

Source

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());
Source

pub fn literal_space(self) -> Self

Adds one space character i.e. “ “ to the previous expression.

Source

pub fn end_of_line(self) -> Self

Adds the ending pattern $, asserts position at the end of the string.

Source

pub fn insensitive() -> Self

Creates an EasyRegex instance starting with the (?i) flag.

Source

pub fn multiline() -> Self

Creates an EasyRegex instance starting with the (?m) flag.

Source

pub fn dot_match_newline() -> Self

Creates an EasyRegex instance starting with the (?s) flag.

Source

pub fn ignore_whitespace() -> Self

Creates an EasyRegex instance starting with the (?x) flag.

Source§

impl EasyRegex

Source

pub fn only_the_beginning() -> Self

Creates an EasyRegex instance starting with the \A character, asserts position at start of the string.

Source

pub fn word_boundary(self) -> Self

Adds the \b metacharacter, asserts position at a word boundary.

Source

pub fn word(self, settings: &Settings) -> Self

Adds the \w metacharacter, matches any word character [a-zA-Z0-9_].

Source

pub fn non_word(self, settings: &Settings) -> Self

Adds the \w metacharacter, matches any non-word character [^a-zA-Z0-9_].

Source

pub fn digit(self, settings: &Settings) -> Self

Adds the \d metacharacter, matches digit character [0-9].

Source

pub fn non_digit(self, settings: &Settings) -> Self

Adds the \D metacharacter, matches any non-digit character [^0-9].

Source

pub fn whitespace(self, settings: &Settings) -> Self

Adds the \s metacharacter, matches any whitespace character [\r\n\t\f\v ].

Source

pub fn non_whitespace(self, settings: &Settings) -> Self

Adds the \S metacharacter, matches any non-whitespace character [^\r\n\t\f\v ].

Source

pub fn non_word_boundary(self) -> Self

Adds the \B metacharacter, asserts position anywhere but NOT at a word boundary.

Source

pub fn only_the_end(self) -> Self

Adds the ending metacharacter \z, asserts position at the end of the text.

Source§

impl EasyRegex

Source

pub fn new(raw: &str) -> Self

Creates an EasyRegex instance, having initial raw pattern.

Source

pub fn new_section() -> Self

Creates an empty EasyRegex instance, useful for start of a pattern.

Source

pub fn get_regex(self) -> Result<Regex, Error>

Retrieves the prepared regular expression as a Result.

Trait Implementations§

Source§

impl Clone for EasyRegex

Source§

fn clone(&self) -> EasyRegex

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EasyRegex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.