본문 바로가기
개발/도구

Regex 정규표현식 정리

by 하요키 2025. 1. 12.
💡 멋진 개발자 엘리님 채널에 업로드된 정규표현식 영상을 보며 실습한 내용을 정리한 글입니다.

 |  또는 \b 단어 경계
() 그룹 \B 단어 경계가 아님
(?:) 찾지만 (group으로) 기억하지는 않음 ^ 문장의 시작
[] 문자셋, 괄호안의 어떤 문자든 $ 문장의 끝
[^] 부정 문자셋, 괄호안의 어떤 문자가 아닐때 .
줄바꿈 문자 제외한 모든 문자
? 없거나, 하나 있거나 (zero or one)
특수 문자열을 검색하고 싶을 때 
* 없거나, 하나 있거나, 많거나 (zero or more) \d
digit 숫자
+ 하나 또는 많이 (one or more) \D 숫자(digit) 아님
{n} n번 반복 \w
word 문자
{min,} 최소 \W
문자(word) 아님
{min,max} 최소, 그리고 최대 \s space 공백
    \S  공백(space) 아님

 

Groups and ranges 그룹, 레인지

 |   또는

 ()  그룹

 (?:)  찾지만 (group으로) 기억하지는 않음

 []  문자셋, 괄호안의 어떤 문자든

 [^]  부정 문자셋, 괄호안의 어떤 문자가 아닐때

 

Quantifiers 수량

 ?  없거나, 하나 있거나 (zero or one)

 *  없거나, 하나 있거나, 많거나 (zero or more)

 +  하나 또는 많이 (one or more)

 {n}  n번 반복

a가 2번 반복되는

 {min,}  최소

a가 최소 2번 반복되는

 {min,max}  최소, 그리고 최대

a가 최소 1번, 최대 2번 반복되는

 

Boundary-type 경계

 \b  단어 경계

단어 앞에서 쓰이는 Ya만!
단어 뒤에서 쓰이는 Ya

 \B  단어 경계가 아님

단어 앞에서 쓰이는 Ya만 제외하고!
단어 뒤에서 쓰이는 Ya만 제외하고!

 ^  문장의 시작

문장의 시작에 있는 Ya만!

 $  문장의 끝

문장의 끝에 있는 Ya만


Character classes

 .  줄바꿈 문자 제외한 모든 문자

 \  특수 문자열을 검색하고 싶을 때 

. 을 찾고 싶다면 앞에 \ 를 붙여야 한다

 \d  digit 숫자

 \D  숫자(digit) 아님

 \w  word 문자

 \W  문자(word) 아님

 \s  space 공백

 \S  공백(space) 아님

Quiz

1. 전화번호

2. 이메일

3. Youtube 주소의 아이디


추가 퀴즈 ⇢

https://regexone.com/

 

RegexOne - Learn Regular Expressions - Lesson 1: An Introduction, and the ABCs

Regular expressions are extremely useful in extracting information from text such as code, log files, spreadsheets, or even documents. And while there is a lot of theory behind formal languages, the following lessons and examples will explore the more prac

regexone.com

https://regexone.com/problem/matching_decimal_numbers

 

RegexOne - Learn Regular Expressions - Problem 1: Matching a decimal numbers

At first glance, writing a regular expression to match a number should be easy right? We have the \d special character to match any digit, and all we need to do is match the decimal point right? For simple numbers, that may be right, but when working with

regexone.com


추가 퀴즈 답 ⇢  

 



유튜브 영상 ⇢ https://youtu.be/t3M6toIflyQ


깃헙 정리
  https://github.com/dream-ellie/regex

 

GitHub - dream-ellie/regex

Contribute to dream-ellie/regex development by creating an account on GitHub.

github.com

연습용 사이트(강의노트)  regexr.com/5mhou

 

RegExr: Learn, Build, & Test RegEx

RegExr is an online tool to learn, build, & test Regular Expressions (RegEx / RegExp).

regexr.com

Flags 세팅
☑️ global (매칭되는 다수의 결과값을 기억합니다.)
☑️ multiline (검색 단위가 문장 단위가 됩니다. 해제하게 되면 ^ 나 $ 검색 시 텍스트 전체를 기준으로 둡니다.)

댓글