■ compile 함수에서 MULTILINE(또는 M) 정규식 컴파일 옵션을 사용하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import re pattern = re.compile("^python\s\w+", re.MULTILINE) data = """python one life is too short python two you need python python three""" result = pattern.findall(data) print(result) """ ['python one', 'python two', 'python three'] """ |
※ re.MULTILINE 옵션을 사용하지 않은 경우 ['python one']만 반환된다.