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

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

2,262  


 


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

 

 


분류 제목
regex PHP 정규표현식 패턴 6강 - \ . (역슬래시 마침표) ─ 단순 문자열로서의 마침표 기호
regex PHP 정규표현식 패턴 5강 - . (마침표) ─ 모든 문자의 1글자에 해당
regex PHP 정규표현식 패턴 4강 - \ (역슬래시) ─ 이스케이프 ★★★★★
regex PHP 정규표현식 패턴 3강 - ^ (꺽쇠) ─ 줄 시작 , $ (달러) ─ 줄 끝
regex PHP 정규표현식 패턴 2강 - 빈칸 구별 함.
regex PHP 정규표현식 패턴 1강 - 대소문자 구별함.
regex PHP 정9/9 - 정규표현식 패턴 (25~26) - 전방 / 후방 탐색
regex PHP 정8/9 - 정규표현식 패턴 (18~24) - 경계
regex PHP 정7/9 - 정규표현식 패턴 (15~17) - 수량자2 ─ {숫자} , {숫자,숫자} , {숫자,} …
regex PHP 62강 - 정규표현식 치환2 (배열 대응 치환) ★★★★★
regex PHP 61강 - 정규표현식 치환1 (= preg_replace 함수 = 프레그리플레이스함수) ★★★★★
regex PHP 60강 - 정규표현식 검색3 (키 활용해 배열 추출) ★★★
regex PHP 59강 - 정규표현식 검색2 (순수도메인 주소 추출) ★★★★★
regex PHP 58강 - 정규표현식 검색 (= preg_match함수 =프레그매치함수) ★★★★★
regex PHP 57강 - 정규표현식 기본 (구분자) + 정규표현식 장단점 ★★★
regex JS 55강 - 정규표현식 (7/7) : 치환
regex JS 54강 - 정규표현식 (6/7) : 캡처
regex JS 53강 - 정규표현식 (5/7) : 옵션
regex JS 52강 - 정규표현식 (4/7) : String 객체의 정규 표현식
regex JS 51강 - 정규표현식 (3/7) : RegExp 객체의 정규 표현식
2/3
목록
찾아주셔서 감사합니다. Since 2012