1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use once_cell::sync::Lazy;
pub use regex::*;

/// 激活码正则
pub static REGEX_ACTIVE_CODE: &'static str = r"^[A-Za-z0-9-]{29}$";
/// IPV4正则
pub static REGEX_IPV4: &'static str = r"^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$";
/// URL正则
pub static REGEX_URL: &'static str = r"^(https?://)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*/?$";
/// 邮箱正则
pub static REGEX_EMAIL: &'static str = r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$";

/// 正则表达式,用于匹配格式化字符串中的占位符
pub static REGEX_FORMAT_PATTERN: Lazy<Regex> = Lazy::new(|| {
  Regex::new(r"\{([a-zA-Z0-9_]+)\}").expect("Invalid regex pattern for REGEX_FORMAT_PATTERN")
});

#[cfg(target_os = "windows")]
/// Windows环境下环境变量的正则表达式
pub static REGEX_ENV_PATTERN: Lazy<Regex> = Lazy::new(|| {
  Regex::new(r"\%([a-zA-Z0-9_]+)\%")
    .expect("Invalid regex pattern for REGEX_ENV_PATTERN on Windows")
});

#[cfg(any(target_os = "linux", target_os = "macos"))]
/// Linux和macOS环境下环境变量的正则表达式
pub static REGEX_ENV_PATTERN: Lazy<Regex> = Lazy::new(|| {
  Regex::new(r"\$\{([a-zA-Z0-9_]+)\}")
    .expect("Invalid regex pattern for REGEX_ENV_PATTERN on Unix-like systems")
});

#[cfg(not(any(target_os = "linux", target_os = "windows", target_os = "macos")))]
/// 对于其他操作系统的环境变量正则表达式
pub static REGEX_ENV_PATTERN: Lazy<Regex> = Lazy::new(|| {
  Regex::new(r"\$([a-zA-Z0-9_]+)")
    .expect("Invalid regex pattern for REGEX_ENV_PATTERN on other systems")
});