文档

Regex Cheatsheet

试用

Comprehensive regex pattern library for common use cases including emails, URLs, phone numbers, dates, passwords, HTML, and more. Use when needing quick copy...

它能做什么

Copy-paste ready regular expressions for common use cases. Test before production use.

技能文档

Regex Pattern Library

Copy-paste ready regular expressions for common use cases. Test before production use.


📧 Email & Contact Patterns

Email Address

# Basic validation
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

# More permissive (real-world)
^[^\s@]+@[^\s@]+\.[^\s@]{2,}$

Phone Numbers

# US phone (123) 456-7890 or 123-456-7890
^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$

# International E.164 format (+1234567890)
^\+?[1-9]\d{1,14}$

URLs

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

# URL (optional protocol)
(https?://)?[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+[^\s]*

# Domain name
^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z]{2,})+$

IP Addresses

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

# IPv6 (simplified)
^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$

📅 Date & Time Patterns

Dates

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

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

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

Times

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

# 24-hour with seconds
^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$

# 12-hour format (HH:MM AM/PM)
^(0?[1-9]|1[0-2]):[0-5]\d\s?(AM|PM|am|pm)$

Timestamps

# ISO 8601 with timezone
^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(Z|[+-]\d{2}:\d{2})$

🔐 Password & Security Patterns

Password Strength

# Minimum 8 chars, at least one letter and one number
^(?=.*[A-Za-z])(?=.*\d).{8,}$

# Minimum 8 chars, uppercase, lowercase, number
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$

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

Common Identifiers

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

# US Social Security Number (SSN)
^\d{3}-\d{2}-\d{4}$

# US ZIP Code
^\d{5}(-\d{4})?$

# UK Postcode
^[A-Z]{1,2}\d[A-Z\d]?\s?\d[A-Z]{2}$

📝 Text Processing Patterns

Whitespace

# Leading whitespace
^\s+

# Trailing whitespace
\s+$

# Multiple spaces (replace with single space)
\s{2,}

# Empty lines
^\s*$

Numbers

# Integer (positive/negative)
^-?\d+$

# Decimal number
^-?\d+(\.\d+)?$

# Currency ($123.45)
^\$?\d{1,3}(,\d{3})*(\.\d{2})?$

# Percentage (12.5%)
^\d+(\.\d+)?%$

Hex Colors

# Hex color (#fff or #ffffff)
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$

# Hex with alpha
^#([A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})$

🌐 HTML & Web Patterns

HTML Tags

# Opening tag
<([a-zA-Z][a-zA-Z0-9]*)\b[^>]*>

# Closing tag
</([a-zA-Z][a-zA-Z0-9]*)>

# Self-closing tag
<([a-zA-Z][a-zA-Z0-9]*)\b[^>]*/>

HTML Comments

<!--[\s\S]*?-->

CSS Classes/IDs

# Class selector
class="([^"]*)"

# ID selector
id="([^"]*)"

Markdown

# Heading level 1-6
^#{1,6}\s.+$

# Bold text
\*\*([^*]+)\*\*

# Italic text
\*([^*]+)\*

# Link
\[([^\]]*)\]\(([^)]*)\)

📂 File & Path Patterns

File Extensions

# Image files
\.(jpg|jpeg|png|gif|bmp|webp|svg)$

# Document files
\.(pdf|doc|docx|txt|xls|xlsx|ppt|pptx)$

# Code files
\.(js|ts|py|java|cpp|c|h|go|rs|rb|php)$

File Paths

# Unix path
^(/[^/]+)+/?$

# Windows path
^[A-Za-z]:\\([^\\]+\\)*[^\\]*$

# Filename (no path)
[^/\\]+$

🔍 Useful Regex Constructs

Lookarounds

# Positive lookahead
foo(?=bar)       # "foo" followed by "bar"

# Negative lookahead
foo(?!bar)       # "foo" NOT followed by "bar"

# Positive lookbehind
(?<=foo)bar      # "bar" preceded by "foo"

# Negative lookbehind
(?<!foo)bar      # "bar" NOT preceded by "foo"

Groups & Capture

# Capture group
(foo|bar)

# Non-capturing group
(?:foo|bar)

# Named group (Python/JS)
(?Ppattern)

# Backreference
(["'])\w+\1      # Matches quoted text with same quotes

💡 Quick Reference Table

PatternRegex
Email^[^\s@]+@[^\s@]+\.[^\s@]{2,}$
URLhttps?://[^\s/$.?#].[^\s]*
IPv4`^((25[0-5]
UUID^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
YYYY-MM-DD^\d{4}-\d{2}-\d{2}$
Hex color^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$

⚠️ Important Notes

  1. Test thoroughly: Always test regex patterns with your specific data
  2. Escape properly: Different languages/engines may require different escaping
  3. Performance: Complex regex can be slow on large inputs
  4. HTML parsing: Regex cannot fully parse HTML - use proper parsers when possible
  5. Email validation: No perfect email regex exists - send verification emails instead
  6. Security: Regex denial-of-service (ReDoS) is possible with certain patterns

Testing Tools

相关技能

把自然语言描述转为结构化 JSON,并由 mcp-diagram-generator MCP 服务生成 Draw.io、Mermaid 或 Excalidraw 图表文件。

作者 nssa.io1.0k 次安装47 星标

以 AI 机器人身份加入视频会议,提供语音、虚拟形象与屏幕共享四种模式。

作者 johnpatternai21 次安装8 星标

在本地磁盘以分类纯 Markdown 文件保存需要长期留存的事实,与智能体内置记忆并存。

作者 Iván555 次安装18 星标

通过一次 REST API 调用,向 10 个社交平台发布视频、图片、文字与文档。

作者 victorcavero14375 次安装50 星标

诊断生产力系统反复失效的根因,给出最小干预——容量测算、瓶颈定位、可靠的本地记录。

作者 Iván854 次安装69 星标

通过托管的 OAuth GraphQL 接口查询与管理 Linear 的 issue、项目、团队、周期、标签和评论。

作者 byungkyu518 次安装18 星标

terrycarter1985 的更多技能

浏览全部技能

为中国小学三到六年级英语书面作业打分,并给出符合年龄的鼓励式反馈。

作者 terrycarter198517 次安装

Analyze stocks and cryptocurrencies using Yahoo Finance data. Supports portfolio management (create, add, remove assets), crypto analysis (Top 20 by market c...

作者 terrycarter198524 次安装

Control whole-house music scenes combining Spotify playback with Airfoil speaker routing. Quick presets for morning, party, chill modes.

作者 terrycarter198519 次安装

Generate reusable, policy-aligned customer service replies for e-commerce aftersales scenarios. Use when support staff need fast, compliant Chinese responses...

作者 terrycarter198518 次安装

Control whole-house music scenes combining Spotify playback with Airfoil speaker routing. Quick presets for morning, party, chill modes.

作者 terrycarter198516 次安装

Comprehensive developer cheatsheets and quick references for Git, Docker, Kubernetes, jq, curl, and common Linux commands. Use when needing quick lookups for...

作者 terrycarter198516 次安装