외계어처럼 보이나요? 괜찮습니다. 필자도 그렇게 보이니까요. 하지만 이 예제에는 중요한 내
용이 많이 들어 있으므로, 시간을 들여 찬찬히 살펴볼 가치가 있습니다. 정규식 시작에는 캡
처하지 않는 그룹
(?:
https
?)?
가 있습니다. 여기에는
0
또는
1
메타 문자(?)가 두 개 있습니
다. 그중 처음은 ‘
s
는 옵션이다’라는 뜻입니다. 일반적으로 반복은 반복 메타 문자의 바로 왼쪽
에 있는 문자
하나
에 적용된다고 했습니다. 두 번째는 그 왼쪽에 있는
그룹 전체
에 적용됩니다.
따라서 이 패턴은 빈 문자열,
http
,
https
에 일치합니다. 다음에는 이스케이프한 슬래시 두 개
(
\
/
\
/
)가 있습니다. 다음에 있는 문자 클래스는 조금 복잡합니다. 도메인 이름에는 글자와 숫
자, 하이픈이 들어갈 수 있지만 시작은 글자여야 하고, 하이픈으로 끝날 수는 없습니다.
이 예제는 완벽하지 않습니다. 예를 들어
//
gotcha
같은, 최상위 도메인이 없는
URL
에도
//
valid
.
com
같은 올바른
URL
과 마찬가지로 일치합니다. 하지만 완벽히 유효한
URL
에만 일
치하는 정규식을 만드는 것은 훨씬 더 복잡한 작업이고 이 예제의 목적에도 맞지 않습니다.
잘못된
URL
에도 일치한다는 경고를 하면서 왜 이런 예제를 제시하는지 궁금한가요? 한 번에 모든 ...
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.