본문 바로가기
개발 관련 강의 정리/유튜브

[드림코딩] 정규표현식 , 더이상 미루지 말자 🤩 정리

by 코딩개발 2023. 7. 9.
728x90
반응형

Groups and ranges

Character
| 또는 gr(e|a)y
() 그룹 (Hi|Hello)|(And)
[] 문자셋, 괄호안의 어떤 문자든 gr[abcd]y, gr[a-f]y, [a-zA-Z0-9]
[^] 부정 문자세, 괄호안의 어떤 문자가 아닐때 [^a-zA-Z0-9]
(?:) 찾지만 기억하지는 않음 gr(?:e|a)y

 

 

Quantifiers

Character
? 없거나 있거나 gra?y
* 없거나 있거나 만거나 gra*y
+ 하나 또는 많이 gra+y
{n} n번 반복 gra{2}y
{min,} 최소 gra{2,3}y
{min, max} 최소, 최대 gra{2,}y

 

 

Boundary-type

Character
\b 단어 경계 \bYa 단어 앞에서 쓰이는 것만
Ya\b 단어 뒤에서 쓰이는 것만
\B 단어 경계가 아님  
^ 문장의 시작 ^Ya
$ 문장의 끝 Ya$

 

 

Character classes

Character
\ 특수 문자가 아닌 문자
. 어떤 글자(줄바꿈 문자 제외)
\d digit 숫자
\D digit 숫자 아님
\w word 문자
\W word 문자 아님
\s space 공백
\S space 공백 아님

 

 

(연습문제)

Hi there, Nice to meet you. And Hello there and hi.
I love grey(gray) color not a gry, graay and graaay.
Ya ya YaYaYa Ya

abcdefghijklmnopqrstuvwxyz
ABSCEFGHIJKLMNOPQRSTUVWZYZ
1234567890

.[]{}()\^$|?*+

010-898-0893
010 405 3412
010.405.3412
010-405-3412
02-878-8888

dr2eam.coder.ellie@gmail.com
hel2lo@daum.net
hel2lo@daum.co.kr

http://www.youtu.be/-ZClicWm0zM
https://www.youtu.be/-ZClicWm0zM
https://youtu.be/-ZClicWm0zM
youtu.be/-ZClicWm0zM

- 전화번호 추출
\d{2,3}[- .]\d{3}[- .]\d{4}

- 이메일 추출
[a-zA-Z0-9._+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9.]+

 

- 유튜브 아이디 추출

(?:https?:\/\/)?(?:www\.)?youtu.be\/([a-zA-Z0-9-]{11})

 

자바스크립트 테스트


참고

https://www.youtube.com/watch?v=t3M6toIflyQ&ab_channel=%EB%93%9C%EB%A6%BC%EC%BD%94%EB%94%A9

https://github.com/dream-ellie/regex

https://regexr.com/5mhou

https://regexone.com/

728x90
반응형

댓글