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
궁금 한 점 이 있 으 시 면 메 시 지 를 남기 거나 본 사이트 의 커 뮤 니 티 에 가서 토론 을 교류 하 세 요.읽 어 주 셔 서 감사합니다. 도움 이 되 셨 으 면 좋 겠 습 니 다.본 사이트 에 대한 지지 에 감 사 드 립 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
로마 숫자를 정수로 또는 그 반대로 변환그 중 하나는 로마 숫자를 정수로 변환하는 함수를 만드는 것이었고 두 번째는 그 반대를 수행하는 함수를 만드는 것이었습니다. 문자만 포함합니다'I', 'V', 'X', 'L', 'C', 'D', 'M' ; 문자열이 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.