일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
27 | 28 | 29 | 30 |
- dfs
- GenAI
- 리트코드
- 파이썬기초100제
- 릿코드
- 알고리즘
- two-pointer
- 코드업
- GenerativeAI
- 슬라이딩윈도우
- 생성형AI
- 파이썬알고리즘
- 자연어처리
- sql코테
- LeetCode
- 구글퀵랩
- Microsoft
- nlp
- heap
- SQL
- Python3
- codeup
- 니트코드
- 투포인터
- Python
- stratascratch
- gcp
- medium
- slidingwindow
- 파이썬
- Today
- Total
Tech for good
[파이썬 정규표현식] re.sub() 본문
re.sub(pattern, repl, string, count, flags)
- re.sub -> '패턴에 일치되는 문자열은 대체 문자열로 바꿔준다.'
- pattern = 패턴
- repl = 대체될 문자열
- string = 문자열 데이터
- count = 최대 몇 개까지 치환할 것인가를 지정
- * (만약 일치되는 문자열이 3인데 count=2라고 지정되어 있으면 마지막 세 번째 문자열은 치환되지 않는다.)
- flags = (아래 블로그 포스팅 표 참조)
Python, Machine & Deep Learning
Python, Machine Learning & Deep Learning
greeksharifa.github.io
# re.sub() 예제
import re
text = """\
010-1234-5678 Kim
011-1234-5678 Lee
016-1234-5678 Han
"""
# flags=re.MULTILINE 지정
text_mod = re.sub('^[0-9]{3}-[0-9]{4}-[0-9]{4}',"***-****-****",text, flags=re.MULTILINE)
print (text_mod)
* 참고
https://docs.python.org/3/library/re.html
re — Regular expression operations — Python 3.10.0 documentation
This module provides regular expression matching operations similar to those found in Perl. Both patterns and strings to be searched can be Unicode strings (str) as well as 8-bit strings (bytes). However, Unicode strings and 8-bit strings cannot be mixed:
docs.python.org
https://ponyozzang.tistory.com/335
Python 정규 표현식(re.sub)을 이용한 문자열 치환 방법 및 예제
파이썬에서 문자열을 치환해주는 메서드로 replace가 있습니다. 이번에는 replace 메서드로 문자열을 치환하는 방법이 아닌 정규 표현식을 이용하여 문자열을 치환해보도록 하겠습니다. 정규 표현
ponyozzang.tistory.com
Python, Machine & Deep Learning
Python, Machine Learning & Deep Learning
greeksharifa.github.io
'IT > Data Science' 카테고리의 다른 글
[Stratascratch/SQL] Daily Interactions By Users Count (0) | 2025.02.26 |
---|---|
[Stratascratch/SQL] Successfully Sent Messages (0) | 2025.02.26 |
.iteritems() 함수 (0) | 2021.10.29 |
[딥러닝을 이용한 자연어 처리 입문] 5. 벡터의 유사도(Vector Similarity) - 2. 여러가지 유사도 기법 (0) | 2021.10.20 |
[딥러닝을 이용한 자연어 처리 입문] 5. 벡터의 유사도(Vector Similarity) - 1. 코사인 유사도(Cosine Similarity) (0) | 2021.10.20 |