feat: all regex patterns have a capture group

This commit is contained in:
graelo 2021-03-27 15:36:48 +01:00
parent 8924af3c51
commit eaeaf5268b
3 changed files with 20 additions and 17 deletions

View file

@ -1,3 +1,7 @@
//! This module defines the regex patterns.
//!
//! All patterns must have one capture group. The first group is used.
use crate::error;
pub(super) const EXCLUDE_PATTERNS: [(&str, &str); 1] =
@ -13,30 +17,30 @@ pub(super) const PATTERNS: [(&str, &str); 17] = [
"url",
r"((https?://|git@|git://|ssh://|ftp://|file:///)[^ \(\)\[\]\{\}]+)",
),
("email", r"\b[A-z0-9._%+-]+@[A-z0-9.-]+\.[A-z]{2,}\b"),
("email", r"\b([A-z0-9._%+-]+@[A-z0-9.-]+\.[A-z]{2,})\b"),
("diff-a", r"--- a/([^ ]+)"),
("diff-b", r"\+\+\+ b/([^ ]+)"),
("docker", r"sha256:([0-9a-f]{64})"),
("path", r"(([.\w\-@~]+)?(/[.\w\-@]+)+)"),
("hexcolor", r"#[0-9a-fA-F]{6}"),
("hexcolor", r"(#[0-9a-fA-F]{6})"),
(
"uuid",
r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
r"([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})",
),
(
"version",
r"(v?\d{1,4}\.\d{1,4}(\.\d{1,4})?(-(alpha|beta|rc)(\.\d)?)?)[^.0-9s]",
),
("ipfs", r"Qm[0-9a-zA-Z]{44}"),
("sha", r"[0-9a-f]{7,40}"),
("ipv4", r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"),
("ipv6", r"[A-f0-9:]+:+[A-f0-9:]+[%\w\d]+"),
("pointer-address", r"0x[0-9a-fA-F]+"),
("ipfs", r"(Qm[0-9a-zA-Z]{44})"),
("sha", r"([0-9a-f]{7,40})"),
("ipv4", r"(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"),
("ipv6", r"([A-f0-9:]+:+[A-f0-9:]+[%\w\d]+)"),
("pointer-address", r"(0x[0-9a-fA-F]+)"),
(
"datetime",
r"(\d{4}-?\d{2}-?\d{2}([ T]\d{2}:\d{2}:\d{2}(\.\d{3,9})?)?)",
),
("digits", r"[0-9]{4,}"),
("digits", r"([0-9]{4,})"),
];
/// Type-safe string Pattern Name (newtype).