정규식 (Regex) 치트시트
대화형 실시간 매처 실습실이 포함된 정규식 구문 및 재사용 가능한 레시피: 앵커, 문자 클래스, 수량자, 전후방 탐색(lookaround) 및 플래그 (ES2024).
동작 원리
A regex engine scans left-to-right trying to satisfy your pattern at each position. Quantifiers (*, +, {n,m}) are greedy by default (consuming as much as possible before backtracking); append `?` to make them lazy, and anchor with `^`/`$` or `\b` when you need exact boundaries.
서바이벌 키트
가장 먼저 배워야 할 몇 가지 명령어입니다.
41개 명령어
Characters & character classes
Match single characters by category (`\d`, `\w`, `\s`) or explicit sets (`[a-f0-9]`). Uppercase shorthands invert the match.
공식 문서: Character classes- 기본
Match a digit, word character ([A-Za-z0-9_]) or whitespace.
\d \w \s사용 시점
Core shorthand character classes used in almost every pattern.
상세 분석
- \d
- ASCII digit [0-9] (uppercase \D = non-digit)
- \w
- alphanumeric + underscore (uppercase \W = non-word)
- \s
- space, tab or newline (uppercase \S = non-whitespace)
예제
Matches dates inside `"release 2026-11-15"`.
\d{4}-\d{2}-\d{2}결과
["2026-11-15"]참고
Anchors & boundaries
Anchors match positions (start/end of string, line or word) rather than consuming characters.
공식 문서: AssertionsQuantifiers & laziness
Control how many times the preceding token repeats. Add `?` after any quantifier to match as few times as possible.
공식 문서: QuantifiersGroups, alternation & backreferences
Parentheses group sub-expressions for quantifiers/alternation and capture text for extraction or backreferences.
공식 문서: Groups and backreferencesLookaheads, lookbehinds & flags
Check what appears ahead or behind the current position without making it part of the matched text.
공식 문서: Assertions & flagsKitLocal 도구에서 사용해 보기
용어집
- Greedy vs Lazy
- `.*` grabs to the last possible match; `.*?` stops at the earliest match.
- Lookaround
- Zero-width assertion (`(?=...)`, `(?!...)`, `(?<=...)`) that checks surrounding text without consuming characters.
- Backtracking
- When a quantifier gives up matched characters so later tokens can match; nested `*`/`+` can cause ReDoS.
- Zero-width
- Tokens like `^`, `$`, `\b` and lookarounds that match a position rather than characters.