Skip to content

Commit 9f4d8af

Browse files
committed
Added examples
1 parent 8f4f819 commit 9f4d8af

1 file changed

Lines changed: 138 additions & 0 deletions

File tree

docs/examples.md

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# rexplain Examples
2+
3+
This page demonstrates how rexplain explains, tests, and generates examples for real-world regex patterns.
4+
5+
---
6+
7+
## Email Address
8+
9+
**Pattern:**
10+
```
11+
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
12+
```
13+
14+
**Explanation:**
15+
```
16+
^ - asserts position at the start of a line
17+
[a-zA-Z0-9._%+-]+ - matches any character in the set [a-zA-Z0-9._%+-] one or more times (greedy)
18+
@ - matches the character '@' (ASCII 64) literally (case sensitive)
19+
[a-zA-Z0-9.-]+ - matches any character in the set [a-zA-Z0-9.-] one or more times (greedy)
20+
\. - matches the character '.' (ASCII 46) literally (case sensitive)
21+
[a-zA-Z]{2,} - matches any character in the set [a-zA-Z] 2 to unlimited times
22+
$ - asserts position at the end of a line
23+
```
24+
25+
**Example Matches:**
26+
- user@example.com
27+
- hello.world+test@sub.domain.co
28+
29+
---
30+
31+
## US Phone Number
32+
33+
**Pattern:**
34+
```
35+
^\(\d{3}\) \d{3}-\d{4}$
36+
```
37+
38+
**Explanation:**
39+
```
40+
^ - asserts position at the start of a line
41+
\( - matches the character '(' (ASCII 40) literally (case sensitive)
42+
\d{3} - matches a digit character exactly 3 times
43+
\) - matches the character ')' (ASCII 41) literally (case sensitive)
44+
- matches the character ' ' (ASCII 32) literally (case sensitive)
45+
\d{3} - matches a digit character exactly 3 times
46+
- - matches the character '-' (ASCII 45) literally (case sensitive)
47+
\d{4} - matches a digit character exactly 4 times
48+
$ - asserts position at the end of a line
49+
```
50+
51+
**Example Matches:**
52+
- (123) 456-7890
53+
- (555) 867-5309
54+
55+
---
56+
57+
## URL (Simple)
58+
59+
**Pattern:**
60+
```
61+
https?://[\w.-]+(?:\.[\w\.-]+)+[/\w\.-]*
62+
```
63+
64+
**Explanation:**
65+
```
66+
h - matches the character 'h' (ASCII 104) literally (case sensitive)
67+
t - matches the character 't' (ASCII 116) literally (case sensitive)
68+
t - matches the character 't' (ASCII 116) literally (case sensitive)
69+
p - matches the character 'p' (ASCII 112) literally (case sensitive)
70+
s? - matches the character 's' (ASCII 115) zero or one time (greedy)
71+
: - matches the character ':' (ASCII 58) literally (case sensitive)
72+
/ - matches the character '/' (ASCII 47) literally (case sensitive)
73+
/ - matches the character '/' (ASCII 47) literally (case sensitive)
74+
[\w.-]+ - matches any character in the set [\w.-] one or more times (greedy)
75+
(?:\.[\w\.-]+)+ - a non-capturing group containing:
76+
\. - matches the character '.' (ASCII 46) literally (case sensitive)
77+
[\w\.-]+ - matches any character in the set [\w\.-] one or more times (greedy)
78+
repeated one or more times (greedy)
79+
[/\w\.-]* - matches any character in the set [/\w\.-] zero or more times (greedy)
80+
```
81+
82+
**Example Matches:**
83+
- http://example.com
84+
- https://sub.domain.co.uk/path/to/page
85+
86+
---
87+
88+
## Password (At least 8 chars, 1 digit, 1 uppercase, 1 lowercase)
89+
90+
**Pattern:**
91+
```
92+
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[A-Za-z\d]{8,}$
93+
```
94+
95+
**Explanation:**
96+
```
97+
^ - asserts position at the start of a line
98+
(?=.*[a-z]) - a lookahead group (must be followed by) containing:
99+
.* - matches any character zero or more times (greedy)
100+
[a-z] - matches any character in the set [a-z]
101+
(?=.*[A-Z]) - a lookahead group (must be followed by) containing:
102+
.* - matches any character zero or more times (greedy)
103+
[A-Z] - matches any character in the set [A-Z]
104+
(?=.*\d) - a lookahead group (must be followed by) containing:
105+
.* - matches any character zero or more times (greedy)
106+
\d - matches a digit character
107+
[A-Za-z\d]{8,} - matches any character in the set [A-Za-z\d] 8 to unlimited times
108+
$ - asserts position at the end of a line
109+
```
110+
111+
**Example Matches:**
112+
- Password1
113+
- Abcdefg8
114+
- XyZ12345
115+
116+
---
117+
118+
## Date (YYYY-MM-DD)
119+
120+
**Pattern:**
121+
```
122+
^\d{4}-\d{2}-\d{2}$
123+
```
124+
125+
**Explanation:**
126+
```
127+
^ - asserts position at the start of a line
128+
\d{4} - matches a digit character exactly 4 times
129+
- - matches the character '-' (ASCII 45) literally (case sensitive)
130+
\d{2} - matches a digit character exactly 2 times
131+
- - matches the character '-' (ASCII 45) literally (case sensitive)
132+
\d{2} - matches a digit character exactly 2 times
133+
$ - asserts position at the end of a line
134+
```
135+
136+
**Example Matches:**
137+
- 2023-01-01
138+
- 1999-12-31

0 commit comments

Comments
 (0)