1pub struct Recipe {
2 pub name: &'static str,
3 pub pattern: &'static str,
4 pub description: &'static str,
5 pub test_string: &'static str,
6}
7
8pub const RECIPES: &[Recipe] = &[
9 Recipe {
10 name: "Email address",
11 pattern: r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}",
12 description: "Match email addresses",
13 test_string: "Contact us at hello@example.com or support@company.co.uk",
14 },
15 Recipe {
16 name: "URL (http/https)",
17 pattern: r"https?://[^\s/$.?#].[^\s]*",
18 description: "Match HTTP and HTTPS URLs",
19 test_string: "Visit https://example.com or http://docs.rs/regex/latest",
20 },
21 Recipe {
22 name: "IPv4 address",
23 pattern: r"\b(?:\d{1,3}\.){3}\d{1,3}\b",
24 description: "Match IPv4 addresses (basic)",
25 test_string: "Server at 192.168.1.1 and gateway 10.0.0.1",
26 },
27 Recipe {
28 name: "Date (YYYY-MM-DD)",
29 pattern: r"\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])",
30 description: "Match ISO 8601 dates",
31 test_string: "Created on 2024-01-15, updated 2024-12-31",
32 },
33 Recipe {
34 name: "Phone number (US)",
35 pattern: r"\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}",
36 description: "Match US phone numbers in common formats",
37 test_string: "Call (555) 123-4567 or 555.987.6543",
38 },
39 Recipe {
40 name: "UUID",
41 pattern: r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}",
42 description: "Match UUIDs (v1-v5)",
43 test_string: "ID: 550e8400-e29b-41d4-a716-446655440000",
44 },
45 Recipe {
46 name: "Hex color code",
47 pattern: r"#(?:[0-9a-fA-F]{3}){1,2}\b",
48 description: "Match 3 or 6 digit hex color codes",
49 test_string: "Colors: #fff, #FF5733, #a1b2c3",
50 },
51 Recipe {
52 name: "Semantic version",
53 pattern: r"\bv?\d+\.\d+\.\d+(?:-[\w.]+)?(?:\+[\w.]+)?\b",
54 description: "Match semver versions (e.g., 1.2.3, v0.4.0-beta.1)",
55 test_string: "Updated from v1.2.3 to v2.0.0-rc.1+build.42",
56 },
57 Recipe {
58 name: "Log level",
59 pattern: r"\b(?:DEBUG|INFO|WARN(?:ING)?|ERROR|FATAL|TRACE)\b",
60 description: "Match common log levels",
61 test_string: "[ERROR] Connection failed\n[INFO] Server started\n[WARN] Low memory",
62 },
63 Recipe {
64 name: "Key=value pairs",
65 pattern: r#"(\w+)=("[^"]*"|\S+)"#,
66 description: "Match key=value pairs (quoted or unquoted)",
67 test_string: "host=localhost port=8080 name=\"my app\" debug=true",
68 },
69 Recipe {
71 name: "VTT/SRT timestamp",
72 pattern: r"\d{2}:\d{2}:\d{2}\.\d{3} --> \d{2}:\d{2}:\d{2}\.\d{3}",
73 description: "Match WebVTT or SRT subtitle timestamp ranges",
74 test_string: "00:01:23.456 --> 00:01:27.890\nHello world\n00:01:28.000 --> 00:01:32.500",
75 },
76 Recipe {
77 name: "HTML/XML tags",
78 pattern: r"<[^>]+>",
79 description: "Match HTML or XML tags (opening, closing, self-closing)",
80 test_string: "<b>bold</b> and <i class=\"x\">italic</i> and <br/>",
81 },
82 Recipe {
83 name: "Sentence boundaries",
84 pattern: r"(?<=[.?!])\s+",
85 description: "Match whitespace after sentence-ending punctuation",
86 test_string: "Hello world. This is a test! Is it working? Yes.",
87 },
88 Recipe {
89 name: "YouTube video ID",
90 pattern: r"(?:v=|youtu\.be/)([a-zA-Z0-9_-]{11})",
91 description: "Extract YouTube video IDs from URLs",
92 test_string: "https://www.youtube.com/watch?v=dQw4w9WgXcQ and https://youtu.be/jNQXAC9IVRw",
93 },
94 Recipe {
95 name: "IATA airport code",
96 pattern: r"\b[A-Z]{3}\b",
97 description: "Match 3-letter IATA airport codes (uppercase)",
98 test_string: "Fly from JFK to LAX via ORD, not via lowercase abc",
99 },
100 Recipe {
101 name: "Unicode combining marks",
102 pattern: r"[\u0300-\u036f]+",
103 description: "Match Unicode combining diacritical marks (accents, zalgo text)",
104 test_string:
105 "caf\u{0065}\u{0301} na\u{0069}\u{0308}ve r\u{0065}\u{0301}sum\u{0065}\u{0301}",
106 },
107 Recipe {
108 name: "Common emoji",
109 pattern: r"[\x{1F300}-\x{1F9FF}\x{2600}-\x{26FF}\x{2700}-\x{27BF}]",
110 description: "Match common emoji characters (symbols, pictographs)",
111 test_string: "Hello \u{1F680} world \u{1F389} test \u{1F916} done \u{2705}",
112 },
113 Recipe {
114 name: "Markdown heading",
115 pattern: r"^#{1,6}\s+.+$",
116 description: "Match Markdown headings (h1 through h6)",
117 test_string: "# Title\n## Section\n### Subsection\nNot a heading",
118 },
119];