python 에서 정규 표현 식 을 사용 하 는 모든 일치 기능 을 자세히 설명 합 니 다.

python 에서 정규 표현 식 을 사용 하 는 모든 일치 기능 을 자세히 설명 합 니 다.
python 에 서 는 임의의 위치 에 있 는 search()함 수 를 검색 하고 경계 에 있 는 match()함 수 를 검색 하 는 등 일치 하 는 함수 가 많 습 니 다.현재 검색 한 문자 가 내용 과 모두 일치 하 는 것 을 배 워 야 합 니 다.이것 이 바로 fullmatch()함수 입 니 다.
예 는 다음 과 같다.

#python 3.6
#    
#http://blog.csdn.net/caimouse/article/details/51749579
#
import re


text = 'This is some text -- with punctuation.'
pattern = 'is'


print('Text    :', text)
print('Pattern  :', pattern)


m = re.search(pattern, text)
print('Search   :', m)
s = re.fullmatch(pattern, text)
print('Full match :', s)




text = 'is'
print('Text    :', text)
s = re.fullmatch(pattern, text)
print('Full match :', s)


text = 'iss'
print('Text    :', text)
s = re.fullmatch(pattern, text)
print('Full match :', s)

결과 출력 은 다음 과 같 습 니 다:

Text    : This is some text -- with punctuation.
Pattern  : is
Search   : <_sre.SRE_Match object; span=(2, 4), match='is'>
Full match : None
Text    : is
Full match : <_sre.SRE_Match object; span=(0, 2), match='is'>
Text    : iss
Full match : None
궁금 한 점 이 있 으 시 면 메 시 지 를 남기 거나 본 사이트 의 커 뮤 니 티 에 가서 토론 을 교류 하 세 요.읽 어 주 셔 서 감사합니다. 도움 이 되 셨 으 면 좋 겠 습 니 다.본 사이트 에 대한 지지 에 감 사 드 립 니 다!

좋은 웹페이지 즐겨찾기