728x90
반응형
아래는 정규표현식에서 '후방 탐색(look-behind)' 시도하다 발생한 error
코드이다.
# 2. Substitution (교체)
str3 = "010-2343-4444"
result = re.sub("(?<=\d{3}-\d{3,4}-)\d{4}", "****", str3)
그리고 아래는 error
를 잡은 코드이다.
# 2. Substitution (교체)
str3 = "010-2343-4444"
result = re.sub("(?<=\d{3}-\d{4}-)\d{4}", "****", str3)
차이점은 범위를 고정(fix)[-\d{4}-]했음을 알 수 있다. '전방 탐색(look-ahead)'에서는 범위를 고정하지 않아도 되나 '후방 탐색(look-behind)'에서는 범위를 고정해야 한다.
728x90
반응형
SMALL
'Python' 카테고리의 다른 글
TypeError: Seasons.__iter__() missing 1 required positional argument: 'self' (0) | 2024.05.13 |
---|---|
TypeError: sub_process() takes 1 positional argument but 11 were given (0) | 2024.01.25 |
파이썬 코딩 High Level vs. Low Level (0) | 2023.01.18 |
파이썬 코딩 스타일 (0) | 2023.01.17 |
[Jupyter Notebook] TypeError: 'method' object is not subscriptable (0) | 2022.12.09 |