Regex Cheat Sheet
실시간 패턴 테스팅과 원클릭 복사 예제가 포함된 상호작용형 정규식 참조입니다.
라이브 테스터
Anchors
| 패턴 | 설명 | |
|---|---|---|
| ^ | Start of string / line | |
| $ | End of string / line | |
| \b | Word boundary | |
| \B | Non-word boundary | |
| \A | Start of string only | |
| \Z | End of string only |
Quantifiers
| 패턴 | 설명 | |
|---|---|---|
| * | 0 or more times | |
| + | 1 or more times | |
| ? | 0 or 1 time (optional) | |
| {n} | Exactly n times | |
| {n,} | n or more times | |
| {n,m} | Between n and m times | |
| *? | Lazy 0 or more | |
| +? | Lazy 1 or more |
Character Classes
| 패턴 | 설명 | |
|---|---|---|
| . | Any character except newline | |
| \d | Digit [0-9] | |
| \D | Non-digit | |
| \w | Word char [a-zA-Z0-9_] | |
| \W | Non-word character | |
| \s | Whitespace | |
| \S | Non-whitespace | |
| [abc] | Character set — a, b, or c | |
| [^abc] | Negated set — not a, b, or c | |
| [a-z] | Character range |
Groups & Alternation
| 패턴 | 설명 | |
|---|---|---|
| (abc) | Capturing group | |
| (?:abc) | Non-capturing group | |
| (?<name>abc) | Named capturing group | |
| (?=abc) | Positive lookahead | |
| (?!abc) | Negative lookahead | |
| (?<=abc) | Positive lookbehind | |
| (?<!abc) | Negative lookbehind | |
| a|b | Alternation — a or b |
Flags
| 패턴 | 설명 | |
|---|---|---|
| g | Global — find all matches | |
| i | Case-insensitive | |
| m | Multiline — ^ and $ match line boundaries | |
| s | Dotall — . matches newline too | |
| u | Unicode mode | |
| y | Sticky — match at exact position |
Common Patterns
| 패턴 | 설명 | |
|---|---|---|
| ^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,}$ | Email address | |
| https?:\/\/[\w\-._~:/?#[\]@!$&'()*+,;=%]+ | URL (http/https) | |
| ^\+?[1-9]\d{1,14}$ | Phone number (E.164) | |
| ^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$ | Date (YYYY-MM-DD) | |
| ^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$ | IPv4 address | |
| ^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$ | UUID v4 | |
| ^#(?:[0-9a-fA-F]{3}){1,2}$ | Hex color code | |
| ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$ | Strong password (min 8 chars, upper+lower+digit) |
패턴을 클릭하여 테스터에 로드하세요
이 도구 소개
정규식은 프로그래밍, 데이터 처리, 텍스트 분석 및 수많은 애플리케이션에서 사용되는 강력한 패턴 매칭 언어입니다. 정규식의 간결한 문법과 다양한 특수 문자로 인해 배우기 어려워 보일 수 있지만, 기본 개념——앵커, 수량자, 문자 클래스, 그룹, 선후행——을 이해하면 복잡한 텍스트 문제를 우아하게 해결할 수 있습니다. 이 정규식 치트시트는 가장 필수적인 패턴과 개념을 하나의 대화형 참조로 모았습니다.
정렬된 패턴과 개념을 카테고리별로 탐색하세요: 앵커(^, $, \b), 수량자(*, +, ?, {n,m}), 문자 클래스([...], \d, \s), 그룹 및 캡처(..., ?:...), 선후행(긍정 및 부정). 라이브 패턴 테스터를 사용하여 자신의 테스트 문자열과 정규식을 입력하고 실시간으로 매칭 결과를 강조 표시할 수 있습니다. 단 한 번의 클릭으로 어떤 패턴이든 복사하여 코드나 정규식 디버거에 바로 붙여넣으세요.
문법을 빠르게 확인해야 할 때마다 이 도구를 북마크하세요. 이메일 주소 검증, 로그 파일 파싱, HTML에서 데이터 추출, 지저분한 문자열 정리, 코드 검색 등 어떤 상황에서든 정규식은 필수적입니다. 표시된 패턴은 대부분의 언어(JavaScript, Python, Java, Go 등)와 호환되지만, 구현에 따라 고급 기능이 약간 달라질 수 있습니다.
자주 묻는 질문
코드 구현
import re
# Common regex patterns
email_pattern = r'^[w.-]+@[w.-]+.[a-zA-Z]{2,}$'
url_pattern = r'https?://[w-._~:/?#[]@!$&'()*+,;=%]+'
ipv4_pattern = r'^(?:(?:25[0-5]|2[0-4]d|[01]?dd?).){3}(?:25[0-5]|2[0-4]d|[01]?dd?)$'
# Test email
email = "user@example.com"
if re.match(email_pattern, email):
print(f"{email} is valid")
# Find all matches
text = "Contact us at info@example.com or support@test.org"
emails = re.findall(r'[w.-]+@[w.-]+.[a-zA-Z]{2,}', text)
print("Found emails:", emails)
# Named groups
date_text = "Today is 2024-03-15"
match = re.search(r'(?P<year>d{4})-(?P<month>d{2})-(?P<day>d{2})', date_text)
if match:
print(f"Year: {match.group('year')}, Month: {match.group('month')}")
# Substitution
result = re.sub(r's+', ' ', "hello world foo").strip()
print(result) # "hello world foo"Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.