2019-01-24 13:59:40 +00:00
|
|
|
//! Predefined Regular Expressions
|
|
|
|
//!
|
|
|
|
//! This is a collection of useful regular expressions
|
|
|
|
|
|
|
|
use lazy_static::lazy_static;
|
2019-01-25 09:15:32 +00:00
|
|
|
use regex::Regex;
|
2019-01-24 13:59:40 +00:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! IPV4OCTET { () => (r"(?:25[0-5]|(?:2[0-4]|1[0-9]|[1-9])?[0-9])") }
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! IPV6H16 { () => (r"(?:[0-9a-fA-F]{1,4})") }
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! IPV6LS32 { () => (concat!(r"(?:(?:", IPV4RE!(), "|", IPV6H16!(), ":", IPV6H16!(), "))" )) }
|
|
|
|
|
2019-02-16 11:36:01 +00:00
|
|
|
/// Returns the regular expression string to match IPv4 addresses
|
2019-01-24 13:59:40 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! IPV4RE { () => (concat!(r"(?:(?:", IPV4OCTET!(), r"\.){3}", IPV4OCTET!(), ")")) }
|
|
|
|
|
2019-02-16 11:36:01 +00:00
|
|
|
/// Returns the regular expression string to match IPv6 addresses
|
2019-01-24 13:59:40 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! IPV6RE { () => (concat!(r"(?:",
|
|
|
|
r"(?:(?:", r"(?:", IPV6H16!(), r":){6})", IPV6LS32!(), r")|",
|
|
|
|
r"(?:(?:", r"::(?:", IPV6H16!(), r":){5})", IPV6LS32!(), r")|",
|
|
|
|
r"(?:(?:(?:", IPV6H16!(), r")?::(?:", IPV6H16!(), r":){4})", IPV6LS32!(), r")|",
|
|
|
|
r"(?:(?:(?:(?:", IPV6H16!(), r":){0,1}", IPV6H16!(), r")?::(?:", IPV6H16!(), r":){3})", IPV6LS32!(), r")|",
|
|
|
|
r"(?:(?:(?:(?:", IPV6H16!(), r":){0,2}", IPV6H16!(), r")?::(?:", IPV6H16!(), r":){2})", IPV6LS32!(), r")|",
|
|
|
|
r"(?:(?:(?:(?:", IPV6H16!(), r":){0,3}", IPV6H16!(), r")?::(?:", IPV6H16!(), r":){1})", IPV6LS32!(), r")|",
|
|
|
|
r"(?:(?:(?:(?:", IPV6H16!(), r":){0,4}", IPV6H16!(), r")?::", ")", IPV6LS32!(), r")|",
|
|
|
|
r"(?:(?:(?:(?:", IPV6H16!(), r":){0,5}", IPV6H16!(), r")?::", ")", IPV6H16!(), r")|",
|
|
|
|
r"(?:(?:(?:(?:", IPV6H16!(), r":){0,6}", IPV6H16!(), r")?::", ")))"))
|
|
|
|
}
|
|
|
|
|
2019-02-16 11:36:01 +00:00
|
|
|
/// Returns the regular expression string to match IP addresses (v4 or v6)
|
2019-01-24 13:59:40 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! IPRE { () => (concat!(r"(?:", IPV4RE!(), "|", IPV6RE!(), ")")) }
|
2019-01-25 09:15:32 +00:00
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
pub static ref IP_REGEX: Regex = Regex::new(IPRE!()).unwrap();
|
2019-01-25 10:38:59 +00:00
|
|
|
|
2019-01-25 16:17:30 +00:00
|
|
|
pub static ref SHA256_HEX_REGEX: Regex =
|
|
|
|
Regex::new(r"^[a-f0-9]{64}$")
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
pub static ref SYSTEMD_DATETIME_REGEX: Regex =
|
|
|
|
Regex::new(r"^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$")
|
|
|
|
.unwrap();
|
2019-01-25 09:15:32 +00:00
|
|
|
}
|