티스토리 뷰

공부

[Python] replace (all) string `re.sub`

승가비 2022. 2. 27. 14:10
728x90
re.sub(pattern, repl, string, count=0, flags=0)
import re

str = 'aaa@gmail.com'

print(re.sub('[a-z]*@', 'ApD@', str))



ApD@gmail.com

https://appdividend.com/2022/01/27/python-regex-replace/

 

Python regex replace: How to replace String in Python

To replace a string in Python using regex(regular expression), we can use the regex sub() method. If you use the str.replace() method.

appdividend.com

 

728x90
댓글