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

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

2,307  


 


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

 

 


분류 제목
PHP-서기 php 30. SQL - PHP로 DB 테이블에 값 추가 (=데이터 넣기)
PHP-서기 php 29. SQL - phpmyadmin으로 테이블 만들기
PHP-서기 php 28. SQL - SQL 의미, DB생성, phpmyadmin 설치
PHP-서기 php 27. 기본적인 환경변수들
PHP-서기 php 26. 쿠키의 시간제한
PHP-서기 php 25. 회원가입처리 / 로그인 구현
PHP-서기 php 24. 쿠키 사용
PHP-서기 php 23. 파일을 이용한 간단한 카운터 제작하기
PHP-서기 php 22. 다른 사이트의 특정부위만 가져오기 - 네이버 인기검색어 파싱 ★
PHP-서기 php 21. 파일을 이용한 메모장 만들기 #3 - 최근글이 가장 위에 오는 메모장 ☆
PHP-서기 php 20. 파일을 이용한 메모장 만들기 #2 ☆
PHP-서기 php 19. 파일을 이용한 메모장 만들기 #1 ☆
PHP-서기 php 18. 파일의 생성과 사용 ☆
PHP-서기 php 17. 배열변수의 사용 ★★★★★
PHP-서기 php 16. for 반복문의 사용, 흐름 ★★★★★★★★★★
PHP-서기 php 15. 여러개의 파일을 이용한 설문조사 ★★★★★
PHP-서기 php 14. 여러개의 파일을 거쳐서 값전달하기 ★★★★★
PHP-서기 php 13. if문을 이용한 수우미양가 출력하기
PHP-서기 php 12. if문의 사용 (= if문의 흐름)
PHP-서기 php 11. 메일 발송하기 ★
13/35
목록
찾아주셔서 감사합니다. Since 2012