跳至正文

正規表示式庫

常用正規表示式模式集合。搜尋並複製即可使用!

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 - 多行模式

注意事項

  • 正規表示式不完美 - 複雜驗證可能需要額外邏輯
  • 在大文字上使用時要小心,可能影響效能
  • 不要僅依賴客戶端驗證;伺服器端驗證也是必需的

相關工具

貢獻

如果您有更有用的正規表示式模式,請建議!