re.sub(pattern,replacement,string) re.sub finds all matches of pattern in string and replaces them with replacement. #Example re.sub("[^0-9]","","abcd1234") #Returns 1234