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

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

2,304  


 


 패턴 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-서기 JQ 4강 - 허버메뉴
JS-서기 JQ 3강 - 이벤트, 이펙트 (=메서드)
JS-서기 JQ 2강 - JQUERY (제이쿼리) 다운로드, 외부링크, 기본구문
JS-서기 JQ 1강 - JQUERY (제이쿼리) 개념, CSS 선택자
JS-서기 JS 17강 - 허버메뉴만들기
JS-서기 JS 16강 - this객체, 조건분기, 속성설정
JS-서기 JS 15강 - CSS 선택자
JS-서기 JS 14강 - HTML CSS JS 혼용하기 (=getElementsBy 시리즈 = JS선택자) ★★★★★
JS-서기 JS 13강 - DOM (돔: Document Object Model 문서객체모델)
JS-서기 JS 12강 - 이벤트핸들러2 (event handler) - onload, onunload, / confi…
JS-서기 JS 11강 - 이벤트핸들러1 (event handler)
JS-서기 JS 10강 - 사용자정의함수 (조건, 경고창, 페이지이동) (function, if, alert, url,…
JS-서기 JS 9강 - 함수 제작 (= 사용자정의함수)
JS-서기 JS 8강 - for문 안쪽에 if문 사용 (= 행렬 표만들기 = 줄바꿈 = 줄바꾸기 = 줄변경 = 라인변…
JS-서기 JS 7강 - 모든 구구단 (= 중첩포문 = 이중포문 = 이단포문) (for double loop)
JS-서기 JS 6강 - 특정 구구단
JS-서기 JS 5강 - for반복문 흐름, 1~100 출력 및 합산 3
JS-서기 JS 4강 - else if 조건문, && 기호 의미
JS-서기 JS 3강 - 변수선언, prompt() 입력함수, if조건문, 사이트 이동 ★
JS-서기 JS 2강 - 변수 선언 및 출력
11/35
목록
찾아주셔서 감사합니다. Since 2012