Skip to content

Commit a267834

Browse files
committed
Added more obscure regex features
1 parent 5d69942 commit a267834

File tree

10 files changed

+978
-145
lines changed

10 files changed

+978
-145
lines changed

Changes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
Revision history for Data-Random-String-Matches
22

3+
0.02
4+
Added more obscure regex features
5+
36
0.01 Mon Oct 27 21:11:53 EDT 2025
47
First draft

MANIFEST

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ MANIFEST.SKIP
1010
README.md
1111
t/30-basics.t
1212
t/40-advanced.t
13+
t/advanced-features.t
14+
t/advanced_regex.t
1315
t/cli.t
1416
t/eof.t
1517
t/eol.t
1618
t/generate.t
19+
t/pod-synopsis.t
1720
t/pod.t

Makefile.PL

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ WriteMakefile(
2828
},
2929
EXE_FILES => ['bin/random-string', 'bin/cookbook'],
3030
TEST_REQUIRES => {
31+
'File::Temp' => 0,
3132
'IPC::Run3' => 0,
3233
'Test::Compile' => 0,
3334
'Test::DescribeMe' => 0,

bin/cookbook

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Run this script to see examples of various patterns:
2222
Or use individual patterns in your own code:
2323
2424
use Data::Random::String::Matches;
25-
25+
2626
# Pick any pattern from above
2727
my $gen = Data::Random::String::Matches->new(qr/[A-Z]{3}\d{4}/);
2828
my $result = $gen->generate();

doc/cookbook.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Quick Pattern Reference
2+
3+
A handy reference for common regex patterns to use with Data::Random::String::Matches.
4+
5+
## Table of Contents
6+
7+
- [Numbers](#numbers)
8+
- [Letters](#letters)
9+
- [Mixed Alphanumeric](#mixed-alphanumeric)
10+
- [Identifiers](#identifiers)
11+
- [Contact Information](#contact-information)
12+
- [Financial](#financial)
13+
- [Passwords](#passwords)
14+
- [Codes & References](#codes--references)
15+
- [Web & URLs](#web--urls)
16+
- [Technical](#technical)
17+
- [Dates & Times](#dates--times)
18+
19+
---
20+
21+
## Numbers
22+
23+
| Pattern | Description | Example Output |
24+
|---------|-------------|----------------|
25+
| `\d{4}` | 4-digit number | 1234 |
26+
| `\d{6}` | 6-digit number | 123456 |
27+
| `[1-9]\d{3}` | 4-digit, no leading zero | 5432 |
28+
| `\d{3}-\d{3}-\d{4}` | Phone format | 555-123-4567 |
29+
| `\d{5}` | ZIP code | 12345 |
30+
| `\d{5}-\d{4}` | ZIP+4 | 12345-6789 |
31+
32+
## Letters
33+
34+
| Pattern | Description | Example Output |
35+
|---------|-------------|----------------|
36+
| `[A-Z]{3}` | 3 uppercase letters | ABC |
37+
| `[a-z]{5}` | 5 lowercase letters | hello |
38+
| `[A-Z][a-z]{4}` | Title case word | Hello |
39+
| `[a-z]{3,8}` | 3-8 lowercase letters | word |
40+
41+
## Mixed Alphanumeric
42+
43+
| Pattern | Description | Example Output |
44+
|---------|-------------|----------------|
45+
| `[A-Za-z0-9]{8}` | 8 mixed chars | aB3cD9eF |
46+
| `[A-Z0-9]{6}` | 6 uppercase + digits | A1B2C3 |
47+
| `[A-Z]{3}\d{4}` | 3 letters + 4 digits | ABC1234 |
48+
| `\w{10}` | 10 word chars | aB3_cD9eF_ |
49+
50+
## Identifiers
51+
52+
| Pattern | Description | Example Output |
53+
|---------|-------------|----------------|
54+
| `AIza[0-9A-Za-z_-]{35}` | Google API key style | AIzaSyB1c2D3e4F5g6H7i8J9k0L1m2N3o4P5 |
55+
| `[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}` | UUID v4 | 550e8400-e29b-41d4-a716-446655440000 |
56+
| `[0-9a-f]{7}` | Git short hash | a1b2c3d |
57+
| `[A-Z]{3}\d{10}` | Database ID | ABC1234567890 |
58+
| `[A-Za-z0-9]{32}` | Session token | aB3cD9eFgH1iJ2kL3mN4oP5qR6sT7uV8 |
59+
60+
## Contact Information
61+
62+
| Pattern | Description | Example Output |
63+
|---------|-------------|----------------|
64+
| `\d{3}-\d{3}-\d{4}` | US Phone | 555-123-4567 |
65+
| `\+1-\d{3}-\d{3}-\d{4}` | US Phone (intl) | +1-555-123-4567 |
66+
| `\(\d{3}\) \d{3}-\d{4}` | US Phone (formatted) | (555) 123-4567 |
67+
| `[a-z]{5,10}@[a-z]{5,10}\.com` | Simple email | hello@world.com |
68+
| `[a-z]{5,10}@(gmail\|yahoo\|hotmail)\.com` | Email with domains | user@gmail.com |
69+
| `\d{5}` | US ZIP | 12345 |
70+
| `[A-Z]{2} \d[A-Z] \d[A-Z]\d` | Canadian postal | K1A 0B1 |
71+
72+
## Financial
73+
74+
| Pattern | Description | Example Output |
75+
|---------|-------------|----------------|
76+
| `4\d{15}` | Visa test card | 4123456789012345 |
77+
| `5[1-5]\d{14}` | Mastercard test | 5412345678901234 |
78+
| `\d{4}-\d{4}-\d{4}-\d{4}` | Card formatted | 1234-5678-9012-3456 |
79+
| `\d{3}` | CVV | 123 |
80+
| `\d{10,12}` | Bank account | 1234567890 |
81+
| `TXN[A-Z0-9]{12}` | Transaction ID | TXNA1B2C3D4E5F6 |
82+
83+
## Passwords
84+
85+
| Pattern | Description | Example Output |
86+
|---------|-------------|----------------|
87+
| `[A-Za-z0-9]{12}` | Simple 12-char | aB3cD9eFgH1i |
88+
| `[A-Za-z0-9!@#$%^&*]{16}` | Strong 16-char | aB3!cD9@eFgH#1iJ |
89+
| `[A-Z][a-z]{3}\d{4}` | Temp password | Pass1234 |
90+
| `[a-z]{4,8}-[a-z]{4,8}-[a-z]{4,8}` | Passphrase | word-another-third |
91+
| `[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}` | Recovery code | A1B2-C3D4-E5F6 |
92+
93+
## Codes & References
94+
95+
| Pattern | Description | Example Output |
96+
|---------|-------------|----------------|
97+
| `ORD-\d{8}` | Order number | ORD-12345678 |
98+
| `INV-\d{4}-[A-Z]{3}` | Invoice number | INV-2024-ABC |
99+
| `(SAVE\|DEAL\|SALE)\d{2}[A-Z]{3}` | Coupon code | SAVE10ABC |
100+
| `[A-Z]{2}-\d{4}-[A-Z]{2}` | Product SKU | AB-1234-CD |
101+
| `SN[A-Z0-9]{10}` | Serial number | SNA1B2C3D4E5 |
102+
| `CONF-[A-Z0-9]{6}` | Confirmation | CONF-A1B2C3 |
103+
104+
## Web & URLs
105+
106+
| Pattern | Description | Example Output |
107+
|---------|-------------|----------------|
108+
| `[a-z]{5,10}\.example\.com` | Subdomain | hello.example.com |
109+
| `[A-Za-z0-9]{6}` | Short URL code | aB3cD9 |
110+
| `[a-z]{3,8}\d{2,4}` | Username | user123 |
111+
| `[a-z]{4,8}-[a-z]{4,8}` | URL slug | some-slug |
112+
| `[a-z0-9]{8,16}` | Username (strict) | user1234 |
113+
114+
## Technical
115+
116+
| Pattern | Description | Example Output |
117+
|---------|-------------|----------------|
118+
| `\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}` | IPv4 address | 192.168.1.1 |
119+
| `[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}` | MAC address | 00:1A:2B:3C:4D:5E |
120+
| `\d{1,2}\.\d{1,2}\.\d{1,3}` | Version number | 1.2.345 |
121+
| `#[0-9A-F]{6}` | Hex color | #FF5733 |
122+
| `[0-9a-f]{32}` | MD5 hash | 5d41402abc4b2a76b9719d911017c592 |
123+
| `[0-9a-f]{40}` | SHA-1 hash | 356a192b7913b04c54574d18c28d46e6395428ab |
124+
125+
## Dates & Times
126+
127+
| Pattern | Description | Example Output |
128+
|---------|-------------|----------------|
129+
| `20\d{2}-(0[1-9]\|1[0-2])-(0[1-9]\|[12]\d\|3[01])` | Date YYYY-MM-DD | 2024-03-15 |
130+
| `(0[1-9]\|1[0-2])/([0-2]\d\|3[01])/\d{4}` | Date MM/DD/YYYY | 03/15/2024 |
131+
| `([01]\d\|2[0-3]):[0-5]\d` | Time HH:MM | 14:30 |
132+
| `([01]\d\|2[0-3]):[

0 commit comments

Comments
 (0)