Enum magic_regexp::Input
source · pub enum Input {
OneOrMore(Type),
Exactly(Type),
Maybe(Type),
}
Expand description
This is a regex input that can be used to match a single character or a group of characters.
Can be used to create a regex that matches a single character or a group of characters.
For example, Input::Exactly(Type::Digit)
will match a single digit.
Example
use magic_regexp::{create_reg_exp, Input, Type};
let regex = create_reg_exp(Input::Exactly(Type::Digit)).unwrap();
assert!(regex.is_match("1"));
assert!(!regex.is_match("12"));
assert!(regex.is_match("1 2"));
Example
use magic_regexp::{create_reg_exp, Input, Type};
let regex = create_reg_exp(Input::OneOrMore(Type::Digit)).unwrap();
assert!(regex.is_match("1"));
assert!(regex.is_match("12"));
assert!(regex.is_match("1 2"));
Example
use magic_regexp::{create_reg_exp, Input, Type};
let regex = create_reg_exp(Input::Maybe(Type::Digit)).unwrap();
assert!(regex.is_match("1"));
assert!(regex.is_match(""));
assert!(regex.is_match("12"));
assert!(regex.is_match("a"));
assert!(regex.is_match("1 2"));
Variants§
Trait Implementations§
source§impl Condition for Input
impl Condition for Input
Returns a Regex, which chains the 2 given regexes with an and
operator.
Example
use magic_regexp::{create_reg_exp, Condition, Exactly, Digit, LetterLowercase};
let regex = create_reg_exp(Exactly(Digit).or(Exactly(LetterLowercase))).unwrap();
assert!(regex.is_match("1"));
assert!(regex.is_match("a"));
assert!(!regex.is_match("A"));
assert!(!regex.is_match("12"));
assert!(!regex.is_match("1a"));
assert!(regex.is_match("1 a"));
source§fn and(self, other: impl AsRegex) -> Regex
fn and(self, other: impl AsRegex) -> Regex
Returns the regex, which chains the two given statements with an
and
condition.source§fn or(self, other: impl AsRegex) -> Regex
fn or(self, other: impl AsRegex) -> Regex
Returns the regex, which chains the two given statements with an
or
condition.source§fn optionally(self) -> Regex
fn optionally(self) -> Regex
Returns the regex, which sets the given statement to optional.
source§impl ToString for Input
impl ToString for Input
source§fn to_string(&self) -> String
fn to_string(&self) -> String
Returns a string representation of the input.
For example, Input::Exactly(Type::Digit)
will return \d
.
Example
use magic_regexp::{Exactly, Digit, AsRegex, create_reg_exp};
let regex = create_reg_exp(Exactly(Digit)).unwrap();
assert!(regex.is_match("1"));
assert!(!regex.is_match("12"));
Example
use magic_regexp::{Input, Type};
let input = Input::Exactly(Type::Text("abc".into()));
assert_eq!(input.to_string(), "abc");
let input = Input::Exactly(Type::Text(".".to_string()));
assert_eq!(input.to_string(), r"\.");
Example
use magic_regexp::{not, OneOrMore, Options};
use regex::Regex;
let input = OneOrMore(not(Options("01".to_string())));
assert_eq!(input.to_string(), r"([^01]+)");
let re = Regex::new(&input.to_string()).unwrap();
assert_eq!(re.replace("1078910", ""), "1010");