Regex Master
Overview
The Regex Master skill covers building correct, readable, and efficient regular expressions for common text processing tasks. It explains character classes, quantifiers, groups, alternation, anchors, and lookahead/lookbehind assertions. It includes a quick-reference library of battle-tested patterns for emails, URLs, dates, phone numbers, IP addresses, and log lines. Every regex is explained token by token so you understand what it does rather than just copying it.
When to Use
- Validating user input (email, phone, postal code, URL)
- Extracting structured data from unstructured text (logs, documents, HTML attributes)
- Search-and-replace with patterns in code editors or scripts
- Parsing delimited or fixed-format text files
- Filtering or transforming data with
grep, sed, awk, Python, or JavaScript
When NOT to Use
- Parsing HTML or XML (use a DOM parser: BeautifulSoup, DOMParser — regex is unreliable for nested structures)
- Parsing programming languages or complex grammars (use a proper parser/AST)
- Matching natural language semantics (use NLP tools)
- When a simple string split or indexOf is sufficient — don't reach for regex when a simpler tool works
Quick Reference
Building Blocks
| Token |
Meaning |
Example |
Matches |
. |
Any character except newline |
a.c |
abc, a1c, a-c |
\d |
Digit [0-9] |
\d+ |
42, 007 |
\w |
Word char [a-zA-Z0-9_] |
\w+ |
hello, foo_2 |
\s |
Whitespace |
\s+ |
space, tab, newline |
\D |
Non-digit |
\D |
a, -, |
\W |
Non-word char |
\W |
!, @, |
\S |
Non-whitespace |
\S+ |
hello, 42 |
^ |
Start of string/line |
^Hello |
Hello world |
$ |
End of string/line |
world$ |
Hello world |
\b |
Word boundary |
\bcat\b |
the cat sat (not catch) |
[abc] |
Character class |
[aeiou] |
any vowel |
[^abc] |
Negated class |
[^0-9] |
any non-digit |
[a-z] |
Range |
[a-zA-Z] |
any letter |
Quantifiers
| Quantifier |
Meaning |
Greedy? |
* |
0 or more |
Yes |
+ |
1 or more |
Yes |
? |
0 or 1 (optional) |
Yes |
{n} |
Exactly n |
Yes |
{n,m} |
Between n and m |
Yes |
{n,} |
n or more |
Yes |
*? |
0 or more |
No (lazy) |
+? |
1 or more |
No (lazy) |
Groups & References
| Syntax |
Meaning |
(abc) |
Capturing group |
(?:abc) |
Non-capturing group |
(?P<name>abc) |
Named capturing group (Python) |
(?<name>abc) |
Named capturing group (JS/PCRE) |
\1, $1 |
Back-reference to group 1 |
a|b |
Alternation: a or b |
Lookaround
| Syntax |
Meaning |
(?=abc) |
Positive lookahead: followed by abc |
(?!abc) |
Negative lookahead: NOT followed by abc |
(?<=abc) |
Positive lookbehind: preceded by abc |
(?<!abc) |
Negative lookbehind: NOT preceded by abc |
Flags
| Flag |
Effect |
i / re.IGNORECASE |
Case-insensitive |
m / re.MULTILINE |
^/$ match line boundaries |
s / re.DOTALL |
. matches newlines |
g |
Global — find all matches (JS) |
x / re.VERBOSE |
Allow whitespace/comments in pattern |
Common Patterns Library
| Pattern |
Regex |
| Email (simple) |
^[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}$ |
| URL |
https?://[\w.-]+(?:/[\w./?=#&%-]*)? |
| IPv4 |
\b(?:\d{1,3}\.){3}\d{1,3}\b |
| Date (YYYY-MM-DD) |
\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01]) |
| Time (HH:MM:SS) |
(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d |
| US Phone |
\+?1?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4} |
| ZIP code (US) |
\d{5}(?:-\d{4})? |
| Credit card |
\b\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}\b |
| Hex color |
#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b |
| UUID |
[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} |
| Semantic version |
\d+\.\d+\.\d+(?:-[\w.]+)?(?:\+[\w.]+)? |
| HTML tag (simple) |
<([a-z][a-z0-9]*)\b[^>]*>(.*?)</\1> |
| Slug |
^[a-z0-9]+(?:-[a-z0-9]+)*$ |
Instructions
Define what to match precisely in plain English first
- What does a valid match look like? (examples)
- What should NOT match? (counter-examples)
- Where in the string must it appear? (anywhere, start, full string)
Build the regex incrementally
- Start with the simplest pattern that matches one known good example.
- Add character classes, quantifiers, and anchors one at a time.
- Test after each addition against both positive and negative examples.
Anchor appropriately
- Use
^...$ for full-string validation (email, phone, slug).
- Omit anchors for searching within a larger text.
- Use
\b for word-boundary matching to avoid partial matches.
Choose capturing vs. non-capturing groups
- Use
(?:...) for grouping without capturing when you don't need the group's value.
- Use named groups
(?P<year>\d{4}) for readability and reliable extraction.
Handle edge cases explicitly
- Optional parts:
(?:\.com)? — the ? makes the group optional.
- Unicode: use
re.UNICODE flag or \p{L} (PCRE2) for non-ASCII letters.
- Newlines: use the
s / DOTALL flag if . should match newlines.
Test thoroughly
- Test against: typical valid input, edge-of-valid input, invalid input that looks similar.
- Use online tools: regex101.com (with detailed explanation), regexr.com.
Document the regex
- Always add a comment explaining what the regex matches.
- Use verbose mode (
re.VERBOSE in Python) to add inline comments for complex patterns.
Examples
Example 1: Validate an email address
Input: "Write a regex to validate email addresses."
Output:
import re
# Email validation regex
# Allows: local part with letters, digits, dots, plus, hyphen
# Requires: @ symbol
# Domain: letters, digits, hyphens
# TLD: 2+ letters
EMAIL_REGEX = re.compile(
r'^[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}$',
re.IGNORECASE
)
# Verbose version explaining each token:
EMAIL_REGEX_VERBOSE = re.compile(r'''
^ # Start of string
[\w.+-]+ # Local part: word chars, dots, plus, hyphen (1 or more)
@ # Literal @ symbol
[\w-]+ # Domain name: word chars and hyphens (1 or more)
\. # Literal dot (escaped)
[a-zA-Z]{2,} # TLD: 2 or more letters
$ # End of string
''', re.VERBOSE | re.IGNORECASE)
def validate_email(email: str) -> bool:
return bool(EMAIL_REGEX.match(email))
# Tests
assert validate_email("alice@example.com") == True
assert validate_email("alice.smith+tag@sub.domain.org") == True
assert validate_email("alice@example.c") == False # TLD too short
assert validate_email("@example.com") == False # Missing local part
assert validate_email("alice@.com") == False # Missing domain
assert validate_email("alice example.com") == False # Missing @
What it matches / rejects:
✅ alice@example.com
✅ alice.smith+filter@sub.domain.co.uk
✅ user123@my-company.io
❌ alice@example.c (TLD must be 2+ chars)
❌ alice @example.com (spaces not allowed)
❌ alice@@example.com (double @)
❌ @example.com (empty local part)
Note: RFC 5321 email validation is extremely complex. This regex covers ~99% of real-world valid addresses. For production, combine with a verification email.
Example 2: Extract data from log lines
Input: Parse Apache Combined Log Format lines:
192.168.1.1 - frank [10/Oct/2024:13:55:36 -0700] "GET /index.html HTTP/1.1" 200 2326 "http://example.com/" "Mozilla/5.0"
Output:
import re
from datetime import datetime
LOG_PATTERN = re.compile(r'''
^
(?P<ip>\d{1,3}(?:\.\d{1,3}){3}) # Client IP address
\s-\s # Separator " - "
(?P<user>\S+) # Remote user (- if none)
\s
\[(?P<timestamp>[^\]]+)\] # Timestamp in brackets
\s
"(?P<method>[A-Z]+) # HTTP method
\s(?P<path>[^\s"]+) # Request path
\s(?P<protocol>HTTP/[\d.]+)" # Protocol
\s
(?P<status>\d{3}) # HTTP status code
\s
(?P<size>\d+|-) # Response size (or - if none)
(?:\s"(?P<referer>[^"]*)")? # Optional referer
(?:\s"(?P<user_agent>[^"]*)")? # Optional user agent
$
''', re.VERBOSE)
def parse_log_line(line: str) -> dict | None:
match = LOG_PATTERN.match(line.strip())
if not match:
return None
data = match.groupdict()
data['status'] = int(data['status'])
data['size'] = int(data['size']) if data['size'] != '-' else 0
return data
# Test
line = '192.168.1.1 - frank [10/Oct/2024:13:55:36 -0700] "GET /index.html HTTP/1.1" 200 2326 "http://example.com/" "Mozilla/5.0"'
result = parse_log_line(line)
print(result)
# {
# 'ip': '192.168.1.1', 'user': 'frank',
# 'timestamp': '10/Oct/2024:13:55:36 -0700',
# 'method': 'GET', 'path': '/index.html',
# 'protocol': 'HTTP/1.1', 'status': 200,
# 'size': 2326, 'referer': 'http://example.com/',
# 'user_agent': 'Mozilla/5.0'
# }
JavaScript equivalent for the same pattern:
const LOG_PATTERN = /^(\d{1,3}(?:\.\d{1,3}){3}) - (\S+) \[([^\]]+)\] "([A-Z]+) ([^\s"]+) (HTTP\/[\d.]+)" (\d{3}) (\d+|-)(?: "([^"]*)")?(?: "([^"]*)")?$/;
function parseLogLine(line) {
const m = line.match(LOG_PATTERN);
if (!m) return null;
const [, ip, user, timestamp, method, path, protocol, status, size, referer, userAgent] = m;
return { ip, user, timestamp, method, path, protocol, status: +status, size: size === '-' ? 0 : +size, referer, userAgent };
}
Best Practices
- Build complex regex with named groups and verbose mode for readability
- Never use regex for HTML/XML parsing — use a DOM parser
- Test with regex101.com for interactive debugging and explanation
- Prefer specific character classes (
[a-z]) over . + filter to avoid surprise matches
- Use lazy quantifiers (
+?, *?) when you need the shortest match, not the longest
- Compile regex patterns once and reuse (
re.compile()) in performance-critical code
Common Mistakes
- Using
.* (greedy) when you want the shortest match — use .*? (lazy)
- Forgetting to escape
. — unescaped . matches any character
- Using
^/$ when multiline mode is needed (they match string boundaries by default, not line boundaries)
- Catastrophic backtracking with nested quantifiers like
(a+)+ on long non-matching input
- Not anchoring validation patterns —
\d+ matches the digits in abc123def
- Using capturing groups
() when non-capturing (?:) is sufficient — wastes memory
Tips & Tricks
- regex101.com shows a detailed token-by-token explanation and live testing
re.fullmatch() in Python is safer than re.match() for validation — no partial matches
- In JavaScript, prefer named groups:
/(?<year>\d{4})-(?<month>\d{2})/ — access via match.groups.year
- Use
sed -E or grep -P for extended/PCRE regex on the command line
- Atomic groups
(?>...) (PCRE) prevent backtracking — useful for catastrophic backtracking prevention
Related Skills
1---2name: regex-master3description: Use this skill when building, explaining, or debugging regular expressions for pattern matching, validation, or text extraction. Trigger phrases: 'write a regex', 'match this pattern', 'validate this format', 'extract from text'. Not for natural language parsing or full grammar parsing (use a parser instead).4license: MIT5---6
7# Regex Master
8
9## Overview
10The Regex Master skill covers building correct, readable, and efficient regular expressions for common text processing tasks. It explains character classes, quantifiers, groups, alternation, anchors, and lookahead/lookbehind assertions. It includes a quick-reference library of battle-tested patterns for emails, URLs, dates, phone numbers, IP addresses, and log lines. Every regex is explained token by token so you understand what it does rather than just copying it.
11
12## When to Use
13- Validating user input (email, phone, postal code, URL)
14- Extracting structured data from unstructured text (logs, documents, HTML attributes)
15- Search-and-replace with patterns in code editors or scripts
16- Parsing delimited or fixed-format text files
17- Filtering or transforming data with `grep`, `sed`, `awk`, Python, or JavaScript
18
19## When NOT to Use
20- Parsing HTML or XML (use a DOM parser: BeautifulSoup, DOMParser — regex is unreliable for nested structures)
21- Parsing programming languages or complex grammars (use a proper parser/AST)
22- Matching natural language semantics (use NLP tools)
23- When a simple string split or indexOf is sufficient — don't reach for regex when a simpler tool works
24
25## Quick Reference
26
27### Building Blocks
28| Token | Meaning | Example | Matches |
29|-------|---------|---------|---------|
30| `.` | Any character except newline | `a.c` | `abc`, `a1c`, `a-c` |
31| `\d` | Digit `[0-9]` | `\d+` | `42`, `007` |
32| `\w` | Word char `[a-zA-Z0-9_]` | `\w+` | `hello`, `foo_2` |
33| `\s` | Whitespace | `\s+` | space, tab, newline |
34| `\D` | Non-digit | `\D` | `a`, `-`, ` ` |
35| `\W` | Non-word char | `\W` | `!`, `@`, ` ` |
36| `\S` | Non-whitespace | `\S+` | `hello`, `42` |
37| `^` | Start of string/line | `^Hello` | `Hello world` |
38| `$` | End of string/line | `world$` | `Hello world` |
39| `\b` | Word boundary | `\bcat\b` | `the cat sat` (not `catch`) |
40| `[abc]` | Character class | `[aeiou]` | any vowel |
41| `[^abc]` | Negated class | `[^0-9]` | any non-digit |
42| `[a-z]` | Range | `[a-zA-Z]` | any letter |
43
44### Quantifiers
45| Quantifier | Meaning | Greedy? |
46|-----------|---------|---------|
47| `*` | 0 or more | Yes |
48| `+` | 1 or more | Yes |
49| `?` | 0 or 1 (optional) | Yes |
50| `{n}` | Exactly n | Yes |
51| `{n,m}` | Between n and m | Yes |
52| `{n,}` | n or more | Yes |
53| `*?` | 0 or more | No (lazy) |
54| `+?` | 1 or more | No (lazy) |
55
56### Groups & References
57| Syntax | Meaning |
58|--------|---------|
59| `(abc)` | Capturing group |
60| `(?:abc)` | Non-capturing group |
61| `(?P<name>abc)` | Named capturing group (Python) |
62| `(?<name>abc)` | Named capturing group (JS/PCRE) |
63| `\1`, `$1` | Back-reference to group 1 |
64| `a\|b` | Alternation: a or b |
65
66### Lookaround
67| Syntax | Meaning |
68|--------|---------|
69| `(?=abc)` | Positive lookahead: followed by abc |
70| `(?!abc)` | Negative lookahead: NOT followed by abc |
71| `(?<=abc)` | Positive lookbehind: preceded by abc |
72| `(?<!abc)` | Negative lookbehind: NOT preceded by abc |
73
74### Flags
75| Flag | Effect |
76|------|--------|
77| `i` / `re.IGNORECASE` | Case-insensitive |
78| `m` / `re.MULTILINE` | `^`/`$` match line boundaries |
79| `s` / `re.DOTALL` | `.` matches newlines |
80| `g` | Global — find all matches (JS) |
81| `x` / `re.VERBOSE` | Allow whitespace/comments in pattern |
82
83### Common Patterns Library
84| Pattern | Regex |
85|---------|-------|
86| Email (simple) | `^[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}$` |
87| URL | `https?://[\w.-]+(?:/[\w./?=#&%-]*)?` |
88| IPv4 | `\b(?:\d{1,3}\.){3}\d{1,3}\b` |
89| Date (YYYY-MM-DD) | `\d{4}-(?:0[1-9]\|1[0-2])-(?:0[1-9]\|[12]\d\|3[01])` |
90| Time (HH:MM:SS) | `(?:[01]\d\|2[0-3]):[0-5]\d:[0-5]\d` |
91| US Phone | `\+?1?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}` |
92| ZIP code (US) | `\d{5}(?:-\d{4})?` |
93| Credit card | `\b\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}\b` |
94| Hex color | `#(?:[0-9a-fA-F]{3}\|[0-9a-fA-F]{6})\b` |
95| UUID | `[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}` |
96| Semantic version | `\d+\.\d+\.\d+(?:-[\w.]+)?(?:\+[\w.]+)?` |
97| HTML tag (simple) | `<([a-z][a-z0-9]*)\b[^>]*>(.*?)</\1>` |
98| Slug | `^[a-z0-9]+(?:-[a-z0-9]+)*$` |
99
100## Instructions
101
1021. **Define what to match precisely in plain English first**
103 - What does a valid match look like? (examples)
104 - What should NOT match? (counter-examples)
105 - Where in the string must it appear? (anywhere, start, full string)
106
1072. **Build the regex incrementally**
108 - Start with the simplest pattern that matches one known good example.
109 - Add character classes, quantifiers, and anchors one at a time.
110 - Test after each addition against both positive and negative examples.
111
1123. **Anchor appropriately**
113 - Use `^...$` for full-string validation (email, phone, slug).
114 - Omit anchors for searching within a larger text.
115 - Use `\b` for word-boundary matching to avoid partial matches.
116
1174. **Choose capturing vs. non-capturing groups**
118 - Use `(?:...)` for grouping without capturing when you don't need the group's value.
119 - Use named groups `(?P<year>\d{4})` for readability and reliable extraction.
120
1215. **Handle edge cases explicitly**
122 - Optional parts: `(?:\.com)?` — the `?` makes the group optional.
123 - Unicode: use `re.UNICODE` flag or `\p{L}` (PCRE2) for non-ASCII letters.
124 - Newlines: use the `s` / `DOTALL` flag if `.` should match newlines.
125
1266. **Test thoroughly**
127 - Test against: typical valid input, edge-of-valid input, invalid input that looks similar.
128 - Use online tools: regex101.com (with detailed explanation), regexr.com.
129
1307. **Document the regex**
131 - Always add a comment explaining what the regex matches.
132 - Use verbose mode (`re.VERBOSE` in Python) to add inline comments for complex patterns.
133
134## Examples
135
136### Example 1: Validate an email address
137
138**Input:** "Write a regex to validate email addresses."
139
140**Output:**
141
142```python
143import re
144
145# Email validation regex
146# Allows: local part with letters, digits, dots, plus, hyphen
147# Requires: @ symbol
148# Domain: letters, digits, hyphens
149# TLD: 2+ letters
150EMAIL_REGEX = re.compile(
151 r'^[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}$',
152 re.IGNORECASE
153)
154
155# Verbose version explaining each token:
156EMAIL_REGEX_VERBOSE = re.compile(r'''
157 ^ # Start of string
158 [\w.+-]+ # Local part: word chars, dots, plus, hyphen (1 or more)
159 @ # Literal @ symbol
160 [\w-]+ # Domain name: word chars and hyphens (1 or more)
161 \. # Literal dot (escaped)
162 [a-zA-Z]{2,} # TLD: 2 or more letters
163 $ # End of string
164''', re.VERBOSE | re.IGNORECASE)
165
166def validate_email(email: str) -> bool:
167 return bool(EMAIL_REGEX.match(email))
168
169# Tests
170assert validate_email("alice@example.com") == True
171assert validate_email("alice.smith+tag@sub.domain.org") == True
172assert validate_email("alice@example.c") == False # TLD too short
173assert validate_email("@example.com") == False # Missing local part
174assert validate_email("alice@.com") == False # Missing domain
175assert validate_email("alice example.com") == False # Missing @
176```
177
178**What it matches / rejects:**
179```
180✅ alice@example.com
181✅ alice.smith+filter@sub.domain.co.uk
182✅ user123@my-company.io
183❌ alice@example.c (TLD must be 2+ chars)
184❌ alice @example.com (spaces not allowed)
185❌ alice@@example.com (double @)
186❌ @example.com (empty local part)
187```
188
189> **Note:** RFC 5321 email validation is extremely complex. This regex covers ~99% of real-world valid addresses. For production, combine with a verification email.
190
191---
192
193### Example 2: Extract data from log lines
194
195**Input:** Parse Apache Combined Log Format lines:
196```
197192.168.1.1 - frank [10/Oct/2024:13:55:36 -0700] "GET /index.html HTTP/1.1" 200 2326 "http://example.com/" "Mozilla/5.0"
198```
199
200**Output:**
201
202```python
203import re
204from datetime import datetime
205
206LOG_PATTERN = re.compile(r'''
207 ^
208 (?P<ip>\d{1,3}(?:\.\d{1,3}){3}) # Client IP address
209 \s-\s # Separator " - "
210 (?P<user>\S+) # Remote user (- if none)
211 \s
212 \[(?P<timestamp>[^\]]+)\] # Timestamp in brackets
213 \s
214 "(?P<method>[A-Z]+) # HTTP method
215 \s(?P<path>[^\s"]+) # Request path
216 \s(?P<protocol>HTTP/[\d.]+)" # Protocol
217 \s
218 (?P<status>\d{3}) # HTTP status code
219 \s
220 (?P<size>\d+|-) # Response size (or - if none)
221 (?:\s"(?P<referer>[^"]*)")? # Optional referer
222 (?:\s"(?P<user_agent>[^"]*)")? # Optional user agent
223 $
224''', re.VERBOSE)
225
226def parse_log_line(line: str) -> dict | None:
227 match = LOG_PATTERN.match(line.strip())
228 if not match:
229 return None
230 data = match.groupdict()
231 data['status'] = int(data['status'])
232 data['size'] = int(data['size']) if data['size'] != '-' else 0
233 return data
234
235# Test
236line = '192.168.1.1 - frank [10/Oct/2024:13:55:36 -0700] "GET /index.html HTTP/1.1" 200 2326 "http://example.com/" "Mozilla/5.0"'
237result = parse_log_line(line)
238print(result)
239# {
240# 'ip': '192.168.1.1', 'user': 'frank',
241# 'timestamp': '10/Oct/2024:13:55:36 -0700',
242# 'method': 'GET', 'path': '/index.html',
243# 'protocol': 'HTTP/1.1', 'status': 200,
244# 'size': 2326, 'referer': 'http://example.com/',
245# 'user_agent': 'Mozilla/5.0'
246# }
247```
248
249JavaScript equivalent for the same pattern:
250```javascript
251const LOG_PATTERN = /^(\d{1,3}(?:\.\d{1,3}){3}) - (\S+) \[([^\]]+)\] "([A-Z]+) ([^\s"]+) (HTTP\/[\d.]+)" (\d{3}) (\d+|-)(?: "([^"]*)")?(?: "([^"]*)")?$/;
252
253function parseLogLine(line) {
254 const m = line.match(LOG_PATTERN);
255 if (!m) return null;
256 const [, ip, user, timestamp, method, path, protocol, status, size, referer, userAgent] = m;
257 return { ip, user, timestamp, method, path, protocol, status: +status, size: size === '-' ? 0 : +size, referer, userAgent };
258}
259```
260
261## Best Practices
262- Build complex regex with named groups and verbose mode for readability
263- Never use regex for HTML/XML parsing — use a DOM parser
264- Test with regex101.com for interactive debugging and explanation
265- Prefer specific character classes (`[a-z]`) over `.` + filter to avoid surprise matches
266- Use lazy quantifiers (`+?`, `*?`) when you need the shortest match, not the longest
267- Compile regex patterns once and reuse (`re.compile()`) in performance-critical code
268
269## Common Mistakes
270- Using `.*` (greedy) when you want the shortest match — use `.*?` (lazy)
271- Forgetting to escape `.` — unescaped `.` matches any character
272- Using `^`/`$` when multiline mode is needed (they match string boundaries by default, not line boundaries)
273- Catastrophic backtracking with nested quantifiers like `(a+)+` on long non-matching input
274- Not anchoring validation patterns — `\d+` matches the digits in `abc123def`
275- Using capturing groups `()` when non-capturing `(?:)` is sufficient — wastes memory
276
277## Tips & Tricks
278- regex101.com shows a detailed token-by-token explanation and live testing
279- `re.fullmatch()` in Python is safer than `re.match()` for validation — no partial matches
280- In JavaScript, prefer named groups: `/(?<year>\d{4})-(?<month>\d{2})/` — access via `match.groups.year`
281- Use `sed -E` or `grep -P` for extended/PCRE regex on the command line
282- Atomic groups `(?>...)` (PCRE) prevent backtracking — useful for catastrophic backtracking prevention
283
284## Related Skills
285- [sql-expert](../sql-expert/SKILL.md)
286- [security-auditor](../security-auditor/SKILL.md)
287- [test-writer](../test-writer/SKILL.md)