Practical regex patterns across languages and use cases. Use when validating input (email, URL, IP), parsing log lines, extracting data from text, refactoring code with search-and-replace, or debugging why a regex doesn't match.
数据来源:ClawHub。 在 ClawSkills 查看
选择你使用的 Agent
方法一:命令行安装(推荐)
推荐(无需提前安装 clawhub)
npx clawhub@latest --dir ~/.claude/skills install regex-patterns或使用 clawhub CLI(需提前安装)
clawhub --dir ~/.claude/skills install regex-patterns⚠️ 需要 Node.js 18+,没有 Node?请使用下方方法二直接下载 ZIP。 安装 Node.js →
方法二:手动下载安装(无需 Node)
下载 ZIP,解压后将文件夹放到以下路径,重启 Agent 即可:
安装路径
~/.claude/skills/regex-patterns/💡解压后将文件夹放到上方路径,重启 Agent 即可生效
--- name: regex-patterns description: Practical regex patterns across languages and use cases. Use when validating input (email, URL, IP), parsing log lines, extracting data from text, refactoring code with search-and-replace, or debugging why a regex doesn't match. metadata: {"clawdbot":{"emoji":"🔤","requires":{"anyBins":["grep","python3","node"]},"os":["linux","darwin","win32"]}} ---
Practical regular expression cookbook. Patterns for validation, parsing, extraction, and refactoring across JavaScript, Python, Go, and command-line tools.
| Pattern | Matches | Example | |---|---|---| | . | Any character (except newline) | a.c matches abc, a1c | | \d | Digit [0-9] | \d{3} matches 123 | | \w | Word char [a-zA-Z0-9_] | \w+ matches hello_123 | | \s | Whitespace [ \t\n\r\f] | \s+ matches spaces/tabs | | \b | Word boundary | \bcat\b matches cat not scatter | | ^ | Start of line | ^Error matches line starting with Error | | $ | End of line | \.js$ matches line ending with .js | | \D, \W, \S | Negated: non-digit, non-word, non-space | |
| Pattern | Meaning | |---|---| | * | 0 or more (greedy) | | + | 1 or more (greedy) | | ? | 0 or 1 (optional) | | {3} | Exactly 3 | | {2,5} | Between 2 and 5 | | {3,} | 3 or more | | *?, +? | Lazy (match as few as possible) |
| Pattern | Meaning | |---|---| | (abc) | Capture group | | (?:abc) | Non-capturing group | | (?P | Named group (Python) | | (? | Named group (JS/Go) | | a\|b | Alternation (a or b) | | [abc] | Character class (a, b, or c) | | [^abc] | Negated class (not a, b, or c) | | [a-z] | Range |
| Pattern | Meaning | |---|---| | (?=abc) | Positive lookahead (followed by abc) | | (?!abc) | Negative lookahead (not followed by abc) | | (?<=abc) | Positive lookbehind (preceded by abc) | | (? | Negative lookbehind (not preceded by abc) |
# Basic (covers 99% of real emails)
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
# Stricter (no consecutive dots, no leading/trailing dots in local part)
^[a-zA-Z0-9]([a-zA-Z0-9._%+-]*[a-zA-Z0-9])?@[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z]{2,})+$
# HTTP/HTTPS URLs
https?://[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*(/[^\s]*)?
# With optional port and query
https?://[^\s/]+(/[^\s?]*)?(\?[^\s#]*)?(#[^\s]*)?
# IPv4
\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b
# IPv4 (simple, allows invalid like 999.999.999.999)
\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b
# IPv6 (simplified)
(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}
# US phone (various formats)
(?:\+1[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}
# Matches: +1 (555) 123-4567, 555.123.4567, 5551234567
# International (E.164)
\+[1-9]\d{6,14}
# ISO 8601 date
\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])
# ISO 8601 datetime
\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})
# US date (MM/DD/YYYY)
(?:0[1-9]|1[0-2])/(?:0[1-9]|[12]\d|3[01])/\d{4}
# Time (HH:MM:SS, 24h)
(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d
# At least 8 chars, 1 upper, 1 lower, 1 digit, 1 special
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+=-]).{8,}$
[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}
\bv?(\d+)\.(\d+)\.(\d+)(?:-([\w.]+))?(?:\+([\w.]+))?\b
# Captures: major, minor, patch, prerelease, build
# Matches: 1.2.3, v1.0.0-beta.1, 2.0.0+build.123
# Apache/Nginx access log
# Format: IP - - [date] "METHOD /path HTTP/x.x" status size
grep -oP '(\S+) - - \[([^\]]+)\] "(\w+) (\S+) \S+" (\d+) (\d+)' access.log
# Extract IP and status code
grep -oP '^\S+|"\s\K\d{3}' access.log
# Syslog format
# Format: Mon DD HH:MM:SS hostname process[pid]: message
grep -oP '^\w+\s+\d+\s[\d:]+\s(\S+)\s(\S+)\[(\d+)\]:\s(.*)' syslog
# JSON log — extract a field
grep -oP '"level"\s*:\s*"\K[^"]+' app.log
grep -oP '"message"\s*:\s*"\K[^"]+' app.log
# Find function definitions (JavaScript/TypeScript)
grep -nP '(?:function\s+\w+|(?:const|let|var)\s+\w+\s*=\s*(?:async\s*)?\([^)]*\)\s*=>|(?:async\s+)?function\s*\()' src/*.ts
# Find class definitions
grep -nP 'class\s+\w+(?:\s+extends\s+\w+)?' src/*.ts
# Find import statements
grep -nP '^import\s+.*\s+from\s+' src/*.ts
# Find TODO/FIXME/HACK comments
grep -rnP '(?:TODO|FIXME|HACK|XXX|WARN)(?:\([^)]+\))?:?\s+' src/
# Find console.log left in code
grep -rnP 'console\.(log|debug|info|warn|error)\(' src/ --include='*.ts' --include='*.js'
# Extract all email addresses from a file
grep -oP '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}' file.txt
# Extract all URLs
grep -oP 'https?://[^\s<>"]+' file.html
# Extract all quoted strings
grep -oP '"[^"\\]*(?:\\.[^"\\]*)*"' file.json
# Extract numbers (integer and decimal)
grep -oP '-?\d+\.?\d*' data.txt
# Extract key-value pairs (key=value)
grep -oP '\b(\w+)=([^\s&]+)' query.txt
# Extract hashtags
grep -oP '#\w+' posts.txt
# Extract hex colors
grep -oP '#[0-9a-fA-F]{3,8}\b' styles.css
// Test if a string matches
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
emailRegex.test('[email protected]'); // true
// Extract with capture groups
const match = '2026-02-03T12:30:00Z'.match(/(\d{4})-(\d{2})-(\d{2})/);
// match[1] = '2026', match[2] = '02', match[3] = '03'
// Named groups
const m = 'John Doe, age 30'.match(/(?<name>[A-Za-z ]+), age (?<age>\d+)/);
// m.groups.name = 'John Doe', m.groups.age = '30'
// Find all matches (matchAll returns iterator)
const text = 'Call 555-1234 or 555-5678';
const matches = [...text.matchAll(/\d{3}-\d{4}/g)];
// [{0: '555-1234', index: 5}, {0: '555-5678', index: 18}]
// Replace with callback
'hello world'.replace(/\b\w/g, c => c.toUpperCase());
// 'Hello World'
// Replace with named groups
'2026-02-03'.replace(/(?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2})/, '$<m>/$<d>/$<y>');
// '02/03/2026'
// Split with regex
'one, two; three'.split(/[,;]\s*/);
// ['one', 'two', 'three']
import re
# Match (anchored to start)
m = re.match(r'^(\w+)@(\w+)\.(\w+)$', '[email protected]')
if m:
print(m.group(1)) # 'user'
# Search (find first match anywhere)
m = re.search(r'\d{3}-\d{4}', 'Call 555-1234 today')
print(m.group()) # '555-1234'
# Find all matches
emails = re.findall(r'[\w.+-]+@[\w.-]+\.\w{2,}', text)
# Named groups
m = re.match(r'(?P<name>\w+)\s+(?P<age>\d+)', 'Alice 30')
print(m.group('name')) # 'Alice'
# Substitution
result = re.sub(r'\bfoo\b', 'bar', 'foo foobar foo')
# 'bar foobar bar'
# Sub with callback
result = re.sub(r'\b\w', lambda m: m.group().upper(), 'hello world')
# 'Hello World'
# Compile for reuse (faster in loops)
pattern = re.compile(r'\d{4}-\d{2}-\d{2}')
dates = pattern.findall(log_text)
# Multiline and DOTALL
re.findall(r'^ERROR.*$', text, re.MULTILINE) # ^ and $ match line boundaries
re.search(r'start.*end', text, re.DOTALL) # . matches newlines
...安装 Regex Patterns 后,可以对 AI 说这些话来触发它
Help me get started with Regex Patterns
Explains what Regex Patterns does, walks through the setup, and runs a quick demo based on your current project
Use Regex Patterns to practical regex patterns across languages and use cases
Invokes Regex Patterns with the right parameters and returns the result directly in the conversation
What can I do with Regex Patterns in my developer & devops workflow?
Lists the top use cases for Regex Patterns, with example commands for each scenario
将技能文件夹放到 ~/.claude/skills/regex-patterns/ 目录(个人级,所有项目可用),或 .claude/skills/regex-patterns/(项目级)。重启 AI 客户端后,用 /regex-patterns 主动调用,或让 AI 根据上下文自动发现并使用。
Regex Patterns 支持 Claude、Cursor、OpenClaw,可与这些 AI 平台无缝集成,扩展其能力。
Regex Patterns 可免费安装使用。请查阅仓库了解许可证信息。
Practical regex patterns across languages and use cases. Use when validating input (email, URL, IP), parsing log lines, extracting data from text, refactoring code with search-and-replace, or debugging why a regex doesn't match.
Regex Patterns 属于「Developer & DevOps」分类,该分类的技能帮助 AI 智能体在此领域执行专业任务。
Automate my developer & devops tasks using Regex Patterns
Identifies repetitive steps in your workflow and sets up Regex Patterns to handle them automatically