Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- 실시간알림
- 성장기
- localStorage
- SSE
- 열공하자
- 파티셔닝
- ServerSentEvent
- Partition
- mariadb
- PostgreSQL
- 개발자
- Lag
- frontend
- node.js
- partitioning
- Node.js기본
- node.js란
- EventSource
Archives
- Today
- Total
써치킴의 우당탕탕 개발 블로그
[JS Level up][Ch3][정규표현식] 패턴(표현) 본문
패턴
- ^ab : 줄(Line) 시작에 있는 ab와 일치
- ab$ : 줄(Line) 끝에 있는 ab와 일치
- . : 임의의 한 문자와 일치
- a|b : a 또는 b와 일치
-
ab? : b가 없거나 b와 일치
-
{3} : 3개 연속 일치
-
{3,} : 3개 이상 연속 일치
-
{3,5} : 3개 이상 5게 이하 연속 일치
-
[abc] : a 또는 b 또는 c
-
[a-z] : a부터 z 사이의 문자 구간에 일치(영어 소문자)
-
[A-Z] : A부터 Z 사이의 문자 구간에 일치(영어 대문자)
-
[0-9] : 0부터 9 사이의 문자 구간에 일치(숫자)
-
[가-힣] : 가부터 힣 사이의 문자 구간에 일치(한글)
-
\w : 63개 문자(Word, 대소영문52개 + 숫자10개 + _)에 일치
-
\b : 63개 문자에 일치하지 않는 문자 경계(Boundary)
-
\d : 숫자(Digit)에 일치
-
\s : 공백(Space, Tab 등)에 일치
-
(?=) : 앞쪽 일치(Lookahead)
-
(?<=) : 뒤쪽 일치(Lookbehind)
const str = `
010-1234-5678
testhello@gmail.com
https://www.omdbapi.com/?apikey=7035c60c&s=frozen
hello searchkim
abbcccdddd
hxyp
http://localhost:8080
동해물과_백두산이 마르고 닳도록`;
console.log(str.match(/d$/gm)); // 끝이 d이면 출력
console.log(str.match(/^h/gm)); // 시작이 h이면 출력
console.log(str.match(/./g)); // 임의의 한 문자하는 단어 출력
console.log(str.match(/h..p/g)); // h??p로 해당하는 단어 출력
console.log(str.match(/search|ddd/g)); // search 또는 ddd가 있으면 출력
console.log(str.match(/https?/g)); // s가 있을수도 있고 없을수도 있는 문자 출력
console.log(str.match(/d{2}/g)); // d가 2개 연속 일치하면 출력
console.log(str.match(/c{2,}/g)); // c가 2개 이상 연속 일치하면 출력
console.log(str.match(/d{2,3}/g)); // d가 2개 이상 3개 이하 연속 일치하면 출력
// \b : 경계(숫자나 문자가 아닌 특수문자에 해당)
// \w : 숫자를 포함한 영어 알파벳을 의미
console.log(str.match(/\b\w{2,3}\b/g));
console.log('==============================================');
console.log(str.match(/[sea]/g)); // s 또는 e 또는 a 일치 문자 출력
console.log(str.match(/[0-9]/g)); // 모든 숫자 출력
console.log(str.match(/[0-9]{1,}/g)); // 숫자 하나 이상 연속되는 문자 출력
console.log(str.match(/[가-힣]{1,}/g)); // 문자 하나 이상 한글 출력
console.log(str.match(/\w/g)); // 대소문자_ 출력
console.log(str.match(/\b/g)); // 경계 출력
console.log(str.match(/\bf\w{1,}\b/g)); // f로 시작하는 단어 출력
console.log(str.match(/\d/g)); // 숫자 출력
console.log(str.match(/\d{1,}/g)); // 숫자 1개 이상 출력
console.log(str.match(/\s/g)); // 공백 출력
const h = ` the hello world !
`;
console.log(h.replace(/\s/g, '')); // 공백 제거
console.log('==============================================');
console.log(str.match(/.{1,}(?=@)/g)); // @ 앞쪽 임의의 문자가 1개 이상
console.log(str.match(/(?<=@).{1,}/g)); // @ 뒤쪽 임의의 문자가 1개 이상
'파도파도 나오는 JavaScript' 카테고리의 다른 글
[JS Bundler][Ch1][Parcel] 프로젝트 생성 (0) | 2022.02.21 |
---|---|
[JS Bundler][Ch1][Parcel] 번들러 개요 (0) | 2022.02.20 |
[JS Level up][Ch3][정규표현식] 메소드 (0) | 2022.02.04 |
[JS Level up][Ch3][정규표현식] 정규식 생성 (0) | 2022.02.04 |
[JS Level up][Ch3][정규표현식] 개요 및 프로젝트 시작 (0) | 2022.02.04 |
Comments