■ 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 |
import re pattern = re.compile(r"(\d{2,3})-(\d{3,4})-(\d{4})") match = pattern.match("02-123-4567") print(match.groups()) # ('02', '123', '4567') print(match.group()) # 02-123-4567 print(match.group(1)) # 02 print(match.start()) # 0 print(match.end()) # 11 print(match.start(2)) # 3 print(match.end(2)) # 6 print(match.string[match.start(2):match.end(3)]) # 123-4567 |