Created
January 29, 2018 18:38
-
-
Save yoneda/009e8cb88c38d1dbfb7fd8507d492d5d to your computer and use it in GitHub Desktop.
replace string using regular expression in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding:utf-8 | |
import re | |
text = "apple_100" | |
anapat = r"(\w+_)(\d+)" | |
reppat = r"\2" | |
result = re.sub(anapat,reppat,text) | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment