fork(1) download
  1. import re
  2.  
  3. pattern = r"\b\d+\b|(\d)"
  4. s = "my text contains of the 33109 following values RT3123SO55 and also with certain numbers godwil_5708 and 323stwe and 8y9yc2 456453"
  5. print(re.sub(pattern, lambda x: 'X' if x.group(1) else x.group(), s))
Success #stdin #stdout 0.02s 9536KB
stdin
Standard input is empty
stdout
my text contains of the 33109 following values RTXXXXSOXX and also with certain numbers godwil_XXXX and XXXstwe and XyXycX 456453