• 회원가입
  • 로그인
  • 구글아이디로 로그인

[regex] PHP 정규표현식 패턴 17강 - 수량자 ─ *? (별표 물음표), +? (덧셈 물음표), ?? (물음표 물음표) 의미

1,959  


 


 패턴 17  -  * , + , ? 패턴 뒤에 ?가 붙으면 해당 의미의 최소값만 선택됨.


Source

One ring to bring them all and in the darkness bind them


Case 1  -  소문자 r 뒤에 어떠한 문자든 0개 이상 

Regular Expression: r.*
First match: One ring to bring them all and in the darkness bind them
All matches: One ring to bring them all and in the darkness bind them

Case 2  -  소문자 r 뒤에 어떠한 문자가 딱 0개,   즉, 오직 r만 선택

Regular Expression: r.*?
First match: One ring to bring them all and in the darkness bind them
All matches: One ring to bring them all and in the darkness bind them


Case 3  -  소문자 r 뒤에 공백 포함 어떠한 문자든 최소 1개 이상 (즉, r 뒤 전부)

Regular Expression: r.+
First match: One ring to bring them all and in the darkness bind them
All matches: One ring to bring them all and in the darkness bind them

Case 4  -  소문자 r 뒤에 어떠한 문자든 1개만,  (즉, r 포함 2글자)

Regular Expression: r.+?
First match: One ring to bring them all and in the darkness bind them
All matches: One ring to bring them all and in the darkness bind them



Case 5  -  소문자 r 뒤에 어떤 문자가 최소 0 , 최대 1개  (즉, r 포함 1 ~ 2 글자)

Regular Expression: r.?
First match: One ring to bring them all and in the darkness bind them
All matches: One ring to bring them all and in the darkness bind them

Case 6  -  소문자 r 뒤에 어떤 문자가 0개,  (즉, 오직 r만 선택)

Regular Expression: r.??
First match: One ring to bring them all and in the darkness bind them
All matches: One ring to bring them all and in the darkness bind them

 

 

 

 

 

 

탐욕적 수량자 (Greedy quantifier)


의미:  가장 끝에 나오는 닫는 태그 앞까지 모두 매칭 검사

패턴 :  <div>.+</div>

매치:  <div>test</div><div>test2</div>

 

 

 

 

 

게으른 수량자 (Lazy quantifier)


의미 :  가장 처음 나오는 닫는 태그 앞까지만 선택해 매칭 검사  

패턴 :  <div>.+?</div>

매치:  <div>test</div><div>test1</div> 

 

 


분류 제목
JS-생코 JS 46강 - UI,API 그리고 문서 (1/2) : 수업소개
JS-생코 JS 45강 - 모듈 (5/5) : 라이브러리의 사용
JS-생코 JS 44강 - 모듈 (4/5) : 라이브러리란?
JS-생코 JS 43강 - 모듈 (3/5) : Node.js의 모듈화
JS-생코 JS 42강 - 모듈 (2/5) : 모듈화
JS-생코 JS 41강 - 모듈 (1/5) : 모듈이란?
JS-생코 JS 40강 - 객체 (3/3) : 객체지향 프로그래밍
JS-생코 JS 39강 - 객체 (2/3) : 객체와 반복문의 조우
JS-생코 JS 38강 - 객체 (1/3) : 객체의 문법
JS-생코 JS 37강 - 배열 (5/5) : 제거와 정렬
JS-생코 JS 36강 - 배열 (4/5) : 데이터의 추가
JS-생코 JS 35강 - 배열 (3/5) : 배열과 반복문의 조우
JS-생코 JS 34강 - 배열 (2/5) : 배열의 효용
JS-생코 JS 33강 - 배열 (1/5) : 배열의 문법
JS-생코 JS 32강 - 함수 (5/5) : 다양한 정의 방법
JS-생코 JS 31강 - 함수 (4/5) : 출력
JS-생코 JS 30강 - 함수 (3/5) : 입력
JS-생코 JS 29강 - 함수 (2/5) : 함수의 효용
JS-생코 JS 28강 - 함수 (1/5) : 함수란?
JS-생코 JS 27강 - 반복 (6/6) : 반복문의 중첩 (= 이중 반복문) ★★★★★
25/35
목록
찾아주셔서 감사합니다. Since 2012