정규식을 ‘큰 문자열에서 부분 문자열을 찾는 방법’이라고만 생각해서는 안 됩니다. 물론 원하
는 것이 그것일 수도 있겠지만, 그런 사고방식이 굳어지면 정규식의 근본적인 성격을 이해하지
못하게 되고 할 수 있는 일도 제한됩니다.
좀 더 나은 개념은 정규식이
입력 문자열을 소비하는 패턴
이라고 생각하는 겁니다. 찾아낸 부
분 문자열은 그렇게 소비한 결과 만들어진 부산물입니다.
어린이들이 글을 배울 때 자주 하는 게임인, 글자를 바둑판 모양으로 늘어놓고 그중에서 단어
를 찾는 게임을 떠올리면 정규식이 어떻게 동작하는지 좀 더 쉽게 이해할 수 있습니다. 세로나
대각선은 무시하고, 바둑판의 맨 윗줄에서만 단어를 찾아봅시다.
X
J
A
N
L
I
O
N
A
T
U
R
E
J
X
E
E
L
N
P
사람은 이런 게임을 아주 쉽게 할 수 있습니다. 쓱 훑어보기만 해도
LION
,
ION
,
NATURE
,
EEL
1
을 찾을 수 있겠죠. 컴퓨터, 그러니까 정규식은 사람 만큼 똑똑하지 않습니다. 정규식의
입장에서 이 게임을 풀어 보면, 정규식이 어떻게 동작하는지 알 수 있고 우리가 주의해야 할 정
규식의 한계도 알 수 있습니다.
단순하게 갑시다. 정규식으로
LION
,
ION
,
NATURE
,
EEL
을 찾는 겁니다. 달리 말해, 답을
알려주고 그 답을 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.