regex

GitHub

提供正则表达式语法、常用模式及多语言用法,用于编写、匹配、验证和提取数据。

data/skills-md/1mangesh1/dev-skills-collection/regex/SKILL.md NeverSight/learn-skills.dev

触发场景

write a regex match pattern validate email extract data with regex parse string

安装

npx skills add NeverSight/learn-skills.dev --skill regex -g -y
更多选项

非标准路径

npx skills add https://github.com/NeverSight/learn-skills.dev/tree/main/data/skills-md/1mangesh1/dev-skills-collection/regex -g -y

不安装直接使用

npx skills use NeverSight/learn-skills.dev@regex

指定 Agent (Claude Code)

npx skills add NeverSight/learn-skills.dev --skill regex -a claude-code -g -y

安装 repo 全部 skill

npx skills add NeverSight/learn-skills.dev --all -g -y

预览 repo 内 skill

npx skills add NeverSight/learn-skills.dev --list

SKILL.md

Frontmatter
{
    "name": "regex",
    "description": "Regular expression mastery with syntax, common patterns, and language-specific usage. Use when user asks to \"write a regex\", \"match pattern\", \"validate email\", \"extract data with regex\", \"parse string\", \"regex for phone number\", or any regular expression tasks."
}

Regular Expressions

Regex syntax, patterns, and recipes.

Core Syntax

Character Classes

.           Any character (except newline)
\d          Digit [0-9]
\D          Non-digit
\w          Word character [a-zA-Z0-9_]
\W          Non-word character
\s          Whitespace [ \t\n\r\f]
\S          Non-whitespace
[abc]       Character set (a, b, or c)
[^abc]      Negated set (not a, b, or c)
[a-z]       Range (a through z)
[a-zA-Z]    Multiple ranges

Quantifiers

*           0 or more
+           1 or more
?           0 or 1
{3}         Exactly 3
{3,}        3 or more
{3,5}       3 to 5
*?          0 or more (lazy/non-greedy)
+?          1 or more (lazy)
??          0 or 1 (lazy)

Anchors & Boundaries

^           Start of string (or line with m flag)
$           End of string (or line with m flag)
\b          Word boundary
\B          Non-word boundary

Groups & References

(abc)       Capture group
(?:abc)     Non-capturing group
(?<name>abc) Named capture group
\1          Backreference to group 1
(?=abc)     Positive lookahead
(?!abc)     Negative lookahead
(?<=abc)    Positive lookbehind
(?<!abc)    Negative lookbehind

Alternation & Escaping

a|b         Match a or b
\           Escape special character
\.          Literal dot
\*          Literal asterisk

Flags

g           Global (all matches)
i           Case-insensitive
m           Multiline (^ and $ match line boundaries)
s           Dotall (. matches newline)
u           Unicode
x           Extended (ignore whitespace, allow comments)

Common Patterns

Validation

# Email (simplified)
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

# URL
^https?://[^\s/$.?#].[^\s]*$

# Phone (US)
^\+?1?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$

# IP Address (IPv4)
^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$

# Date (YYYY-MM-DD)
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$

# Time (HH:MM, 24hr)
^([01]\d|2[0-3]):[0-5]\d$

# UUID
^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$

# Hex color
^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$

# Strong password (8+ chars, upper, lower, digit, special)
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$

# Semantic version
^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*))?$

# Slug (URL-safe string)
^[a-z0-9]+(?:-[a-z0-9]+)*$

Extraction

# Extract domain from URL
https?://([^/\s]+)

# Extract filename from path
[^/\\]+$

# Extract numbers from string
\d+\.?\d*

# Extract HTML tags
<([a-zA-Z][a-zA-Z0-9]*)\b[^>]*>

# Extract key=value pairs
(\w+)=([^\s&]+)

# Extract markdown links
\[([^\]]+)\]\(([^)]+)\)

# Extract CSV fields (handling quotes)
(?:^|,)(?:"([^"]*(?:""[^"]*)*)"|([^,]*))

Language Usage

JavaScript

// Test
/^\d+$/.test("123");                    // true

// Match
"hello world".match(/(\w+)\s(\w+)/);   // ["hello world", "hello", "world"]

// Match all
[..."text 123 more 456".matchAll(/\d+/g)];  // [["123"], ["456"]]

// Replace
"hello".replace(/l/g, "r");            // "herro"
"John Smith".replace(/(\w+) (\w+)/, "$2, $1");  // "Smith, John"

// Split
"a,b,,c".split(/,+/);                  // ["a", "b", "c"]

// Named groups
const m = "2024-01-15".match(/(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/);
m.groups.year;  // "2024"

Python

import re

# Match (from start)
re.match(r'^\d+', '123abc')

# Search (anywhere)
re.search(r'\d+', 'abc123')

# Find all
re.findall(r'\d+', 'a1 b2 c3')          # ['1', '2', '3']

# Find all with groups
re.findall(r'(\w+)=(\w+)', 'a=1 b=2')   # [('a', '1'), ('b', '2')]

# Replace
re.sub(r'\d+', 'X', 'a1b2c3')           # 'aXbXcX'
re.sub(r'(\w+) (\w+)', r'\2 \1', 'John Smith')  # 'Smith John'

# Compile for reuse
pattern = re.compile(r'\b\w{4}\b')
pattern.findall('the quick brown fox')    # ['quick', 'brown']

# Named groups
m = re.search(r'(?P<year>\d{4})-(?P<month>\d{2})', '2024-01')
m.group('year')  # '2024'

# Flags
re.findall(r'hello', 'Hello World', re.IGNORECASE)

Bash/grep

# grep (basic regex)
grep "pattern" file.txt
grep -i "pattern" file.txt       # Case insensitive
grep -E "extended|regex" file.txt  # Extended regex
grep -P "\d{3}" file.txt          # Perl regex (GNU grep)

# sed
sed 's/old/new/g' file.txt
sed -E 's/([0-9]+)/[\1]/g' file.txt

Reference

For more recipes and testing tips: references/recipes.md

版本历史

  • e0220ca 当前 2026-07-05 20:44

同 Skill 集合

data/skills-md/00prabalk00/claude-skills/knowledge-base-gap-finder/SKILL.md
data/skills-md/01000001-01001110/agent-jira-skills/jira-agile/SKILL.md
data/skills-md/01000001-01001110/agent-jira-skills/jira-auth/SKILL.md
data/skills-md/01000001-01001110/agent-jira-skills/jira-issues/SKILL.md
data/skills-md/01000001-01001110/agent-jira-skills/jira-project-management/SKILL.md
data/skills-md/01000001-01001110/agent-jira-skills/jira-projects/SKILL.md
data/skills-md/01000001-01001110/agent-jira-skills/jira-safe/SKILL.md
data/skills-md/01000001-01001110/agent-jira-skills/jira-search/SKILL.md
data/skills-md/01000001-01001110/agent-jira-skills/jira-spaces/SKILL.md
data/skills-md/01000001-01001110/agent-jira-skills/jira-transitions/SKILL.md
data/skills-md/0731coderlee-sudo/wechat-publisher/wechat-publisher/SKILL.md
data/skills-md/0froq/skills/conventionalcommits/SKILL.md
data/skills-md/0froq/skills/nuxt/SKILL.md
data/skills-md/0froq/skills/oq/SKILL.md
data/skills-md/0froq/skills/pinia/SKILL.md
data/skills-md/0froq/skills/pnpm/SKILL.md
data/skills-md/0froq/skills/slidev/SKILL.md
data/skills-md/0froq/skills/tsdown/SKILL.md
data/skills-md/0froq/skills/turborepo/SKILL.md
data/skills-md/0froq/skills/unocss/SKILL.md
data/skills-md/0froq/skills/vitepress/SKILL.md
data/skills-md/0froq/skills/vitest/SKILL.md
data/skills-md/0froq/skills/vue-best-practices/SKILL.md
data/skills-md/0froq/skills/vue-router-best-practices/SKILL.md
data/skills-md/0froq/skills/vue-testing-best-practices/SKILL.md
data/skills-md/0froq/skills/vue/SKILL.md
data/skills-md/0froq/skills/vueuse-functions/SKILL.md
data/skills-md/0froq/skills/web-design-guidelines/SKILL.md
data/skills-md/0juano/agent-skills/bondterminal-x402/SKILL.md
data/skills-md/0juano/agent-skills/edgeone-pages-deploy/SKILL.md
data/skills-md/0juano/agent-skills/ley-ar/SKILL.md
data/skills-md/0juano/agent-skills/ticktick/SKILL.md
data/skills-md/0juano/agent-skills/x-image-cards/SKILL.md
data/skills-md/0juano/x-image-cards/x-image-cards/SKILL.md
data/skills-md/0x0funky/agent-sprite-forge/generate2dsprite/SKILL.md
data/skills-md/0x0funky/agent-sprite-forge/video2dsprite/SKILL.md
data/skills-md/0x2e/superpowers/brainstorming/SKILL.md
data/skills-md/0x2e/superpowers/dispatching-parallel-agents/SKILL.md
data/skills-md/0x2e/superpowers/executing-plans/SKILL.md
data/skills-md/0x2e/superpowers/finishing-a-development-branch/SKILL.md
data/skills-md/0x2e/superpowers/receiving-code-review/SKILL.md
data/skills-md/0x2e/superpowers/requesting-code-review/SKILL.md
data/skills-md/0x2e/superpowers/subagent-driven-development/SKILL.md
data/skills-md/0x2e/superpowers/systematic-debugging/SKILL.md
data/skills-md/0x2e/superpowers/test-driven-development/SKILL.md
data/skills-md/0x2e/superpowers/using-git-worktrees/SKILL.md
data/skills-md/0x2e/superpowers/using-superpowers/SKILL.md
data/skills-md/0x2e/superpowers/verification-before-completion/SKILL.md
data/skills-md/0x2e/superpowers/writing-plans/SKILL.md
data/skills-md/0x2e/superpowers/writing-skills/SKILL.md

元信息

文件数
0
版本
e4a0f95
Hash
4e5c5342
收录时间
2026-07-05 20:44

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-05 03:17
浙ICP备14020137号-1 $访客地图$