Skip to main content

rgx/
recipe.rs

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];