C.W.K.
Stream
Lesson 08 of 10 · published

Flavor 차이 — Lookaround 깨지는 자리

~8 min · flavors, compatibility

Level 0패턴 호기심
0 XP0/90 lessons0/15 achievements
0/100 XP to next level100 XP to go0% complete

Lookaround 가 정규식에서 가장 분열된 기능

"위치 주변 보기" 가 universal 일 줄 알았지. 아냐. 2026 기준 실제 풍경:

엔진LookaheadLookbehindVariable-width Lookbehind
Python re✗ (에러)
Python regex
JavaScript✓ (ES2018)✓ (ES2018)
PCRE부분 (버전 의존)
Java제한 (max 길이 bound 필수)
.NET
Go regexp / RE2
ripgrep (기본)
ripgrep --pcre2부분

Portability 스펙트럼

Universal: Lookaround 없음. Anchor 와 character class 만.

대부분 엔진: Lookahead (positive 와 negative). 거의 항상 지원.

대부분 엔진, 좀 까다: Lookbehind, fixed-width. Python, Java, .NET. 너비 룰 주의.

현대 엔진만: Variable-width lookbehind. JavaScript ES2018+, .NET, Python regex.

절대 NO: Go, RE2. Lookaround 쓰는 패턴 컴파일 안 됨.

실전 조언

본인 코드가 여러 언어에서 돌거나 정규식이 Go 서비스로 갈 가능성이면 lookaround 회피. Anchor, capture, post-processing 사용. 패턴이 더 못 생김 but portable.

한 엔진에 머물면 lookaround 자유롭게 — 많은 문제에 가장 깨끗한 도구.

Code

같은 문제, 다른 엔진·text
# 목표: '$' 앞에 오는 숫자 추출하되 '$' 자체는 스킵

# Python re — 동작
import re
re.findall(r'(?<=\$)\d+', 'paid $19 not 20 but $5')
# ['19', '5']

# JavaScript ES2018+ — 동작
// 'paid $19 not 20 but $5'.match(/(?<=\$)\d+/g)
// ['19', '5']

# Go — 동작 NO, regexp.MustCompile panic
// regexp.MustCompile(`(?<=\$)\d+`)  // panic: error parsing regexp

# Go workaround — 캡처 후 post-process
// re := regexp.MustCompile(`\$(\d+)`)
// matches := re.FindAllStringSubmatch(s, -1)
// for _, m := range matches { fmt.Println(m[1]) }  // m[1] 이 숫자만

External links

Exercise

본인이 작성한 lookaround 패턴 잡기. regex101 통해 세 엔진에 테스트: PCRE2, Python, ECMAScript (JavaScript). 동일 동작, 플래그 변경 필요, 실패 메모. 각각 전략 선택: 회피 재작성 또는 엔진 요구 문서화.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.