跳至正文

正则表达式库

常用正则表达式模式集合。搜索并复制即可使用!

Email

Basic Email

기본 이메일 형식

^[\w\.-]+@[\w\.-]+\.\w+$
Example:user@example.com

RFC 5322 Email

RFC 5322 표준 이메일

^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$
Example:user.name+tag@example.co.kr

URL

HTTP/HTTPS URL

HTTP/HTTPS URL

^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$
Example:https://www.example.com/path?query=value

Domain Name

도메인 이름

^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$
Example:example.com

Phone

Korean Phone

한국 휴대폰 번호

^01[0-9]-?[0-9]{3,4}-?[0-9]{4}$
Example:010-1234-5678

US Phone

미국 전화번호

^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$
Example:(123) 456-7890

International Phone

E.164 국제 전화번호

^\+?[1-9]\d{1,14}$
Example:+821012345678

Date & Time

Date (YYYY-MM-DD)

ISO 8601 날짜 형식

^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$
Example:2024-01-15

Time (HH:MM:SS)

24시간 시간 형식

^([01]\d|2[0-3]):([0-5]\d):([0-5]\d)$
Example:14:30:45

Date (DD/MM/YYYY)

DD/MM/YYYY 형식

^(0[1-9]|[12]\d|3[01])\/(0[1-9]|1[0-2])\/\d{4}$
Example:15/01/2024

Numbers

Integer

정수

^-?\d+$
Example:-123

Decimal

소수

^-?\d*\.?\d+$
Example:123.45

Positive Integer

양의 정수

^[1-9]\d*$
Example:123

Credit Card

신용카드 번호 (Visa, MasterCard, Amex)

^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13})$
Example:4111111111111111

Password

Strong Password

최소 8자, 대소문자, 숫자, 특수문자 포함

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$
Example:Abcd1234!

Medium Password

최소 6자, 영문+숫자

^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d]{6,}$
Example:Abcd1234

Code

IPv4 Address

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]?)$
Example:192.168.1.1

IPv6 Address

IPv6 주소

^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$
Example:2001:0db8:85a3:0000:0000:8a2e:0370:7334

Hex Color

HEX 색상 코드

^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
Example:#FF5733

HTML Tag

HTML 태그

<[^>]+>
Example:<div class="test">

Korean

Hangul Only

한글만

^[가-힣]+$
Example:한글

Korean Name

한국 이름 (2-4자)

^[가-힣]{2,4}$
Example:홍길동

Korean ID (RRN)

주민등록번호

^\d{6}-?[1-4]\d{6}$
Example:901231-1234567

分类

📧 Email

电子邮件地址验证的正则表达式模式

🌐 URL

网址和域名验证模式

📞 Phone

各国电话号码格式模式

📅 Date & Time

日期和时间格式验证模式

🔢 Numbers

数字、整数、小数、信用卡号等

🔐 Password

密码强度验证模式

💻 Code

代码相关模式,如IP地址、颜色代码、HTML标签

🇰🇷 Korean

韩语模式,包括韩文、韩国名字、居民登记号码

使用方法

  1. 选择分类: 点击所需分类按钮
  2. 搜索: 在搜索栏中搜索所需模式
  3. 复制: 点击 📋 按钮复制模式
  4. 测试: 点击 🧪 按钮直接在正则测试器中测试

使用示例

表单验证

const emailRegex = /^[\w\.-]+@[\w\.-]+\.\w+$/;
if (!emailRegex.test(userInput)) {
alert('无效的电子邮件地址');
}

数据提取

const urlRegex = /https?:\/\/[^\s]+/g;
const urls = text.match(urlRegex);

数据清理

const phoneRegex = /^01[0-9]-?[0-9]{3,4}-?[0-9]{4}$/;
const cleanPhone = phone.replace(/-/g, '');

正则表达式提示

常用元字符

  • ^ - 字符串开始
  • $ - 字符串结束
  • . - 任意单个字符
  • * - 0次或多次重复
  • + - 1次或多次重复
  • ? - 0次或1次出现
  • [] - 字符类
  • | - OR运算符
  • () - 分组

标志

  • g - 全局搜索
  • i - 不区分大小写
  • m - 多行模式

注意事项

  • 正则表达式不完美 - 复杂验证可能需要额外逻辑
  • 在大文本上使用时要小心,可能影响性能
  • 不要仅依赖客户端验证;服务器端验证也是必需的

相关工具

贡献

如果您有更有用的正则表达式模式,请建议!