■ match 함수를 사용해 패턴 존재를 검사하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import re text1 = "35th" match1 = re.match("[0-9]*th", text1) if match1 == None: print("일치하지 않습니다.") else: print(match1.string) text2 = " 35th" match2 = re.match("[0-9]*th", text2) if match2 == None: print("일치하지 않습니다.") else: print(match2.string) """ 35th 일치하지 않습니다. """ |