Python Regex after a known string -
i have string formatted such: | birth_date = 22 january 1898 |
i want write regex looks birth_date, , gets 4 digit sequence of digits after birth_date until pipe character
import re print re.sub(r'\d', '', "| birth_date = 22 january 1898 |") # output => 221898 # if want last 4 digits: print re.sub(r'(\d)', '', "| birth_date = 22 january 1898 |")[-4:] # output => 1898
Comments
Post a Comment