fork(1) download
  1. import re
  2. text = "hello23 the2e are 13 5.12apples *specially_x00123 named 31st"
  3. pattern = r"\*[^\W_\n]+_[a-z]\d+\b|(\d)"
  4. print (re.sub(pattern, lambda x: "#" if x.group(1) else x.group(), text))
  5.  
Success #stdin #stdout 0.02s 27712KB
stdin
Standard input is empty
stdout
hello## the#e are ## #.##apples *specially_x00123 named ##st