Replace in String You could parse out sections of a string as follows regex = ^([0-9]{4})([0-9]{7})$ This will replace any 11 digit numbers with the last 7 digits.