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

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

2,265  


 


 패턴 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> 

 

 


분류 제목
코딩 야학 코딩야학 2회 & 생활코딩 라이브 17년 6월 5일
코딩 야학 코딩야학 1회 & 생활코딩 라이브 17년 6월 2일
JS-생코 JS 104강 - Node의 종류 API (3/3) : 재귀함수 2
JS-생코 JS 103강 - Node의 종류 API (2/3) : 재귀함수 1
JS-생코 JS 102강 - Node의 종류 API (1/3) : nodeType, nodeName
JS-생코 JS 101강 - 참조(3/3) : 함수와 참조
JS-생코 JS 100강 - 참조 (2/3) : 참조
JS-생코 JS 99강 - 참조 (1/3) : 복제란?
JS-생코 JS 98강 - 데이터 타입 (2/2) : 레퍼 객체
JS-생코 JS 97강 - 데이터 타입 (1/2) : 원시 데이터 타입과 객체
JS-생코 JS 96강 - Object (4/4) : Object확장의 위험
JS-생코 JS 95강 - Object (3/4) : Object 확장
JS-생코 JS 94강 - Object (2/4) : Object API 사용법
JS-생코 JS 93강 - Object (1/4) : Object란?
JS-생코 JS 92강 - 표준 내장 객체의 확장 (3/3) : 배열의 확장 2
JS-생코 JS 91강 - 표준 내장 객체의 확장 (2/3) : 배열의 확장 1
JS-생코 JS 90강 - 표준 내장 객체의 확장 (1/3) : 표준 내장 객체란?
JS-생코 JS 89강 - prototype (2/2) : prototype chain
JS-생코 JS 88강 - prototype (1/2) : prototype이란?
JS-생코 JS 87강 - 상속 (3/3) : 기능의 추가
22/35
목록
찾아주셔서 감사합니다. Since 2012