Skip to content

Instantly share code, notes, and snippets.

@yoneda
Created January 29, 2018 18:38
Show Gist options
  • Save yoneda/009e8cb88c38d1dbfb7fd8507d492d5d to your computer and use it in GitHub Desktop.
Save yoneda/009e8cb88c38d1dbfb7fd8507d492d5d to your computer and use it in GitHub Desktop.
replace string using regular expression in python
# 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