Skip to content

Commit

Permalink
improve regex
Browse files Browse the repository at this point in the history
  • Loading branch information
sky-2002 committed Dec 19, 2024
1 parent 266e95a commit 2461618
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/json_schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,8 @@ mod tests {
"username@com", // TLD must have at least 2 characters
"username@example,com", // invalid character in domain
"[email protected]", // leading dot in domain
"[email protected]", // domain cannot start with a hyphen
"[email protected]", // domain cannot end with a hyphen
"[email protected]", // double dot in domain name
"[email protected]", // multiple errors in domain
]
Expand Down
3 changes: 1 addition & 2 deletions src/json_schema/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ pub static DATE: &str = r#""(?:\d{4})-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0
pub static TIME: &str = r#""(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\\.[0-9]+)?(Z)?""#;
pub static UUID: &str = r#""[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}""#;
pub static URI: &str = r#"^(https?|ftp):\/\/([^\s:@]+(:[^\s:@]*)?@)?([a-zA-Z\d.-]+\.[a-zA-Z]{2,}|localhost)(:\d+)?(\/[^\s?#]*)?(\?[^\s#]*)?(#[^\s]*)?$|^urn:[a-zA-Z\d][a-zA-Z\d\-]{0,31}:[^\s]+$"#;
pub static EMAIL: &str =
r"^[A-Za-z0-9]+(?:[._%+-][A-Za-z0-9]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,63}$";
pub static EMAIL: &str = r#"^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$"#;

#[derive(Debug, PartialEq)]
pub enum FormatType {
Expand Down

0 comments on commit 2461618

Please sign in to comment.