fork download
  1. import re
  2. list1 = ['apple', 'orange']
  3. text = 'the books are good apple34'
  4. word = re.sub(rf"(?:{'|'.join(map(re.escape, list1))})\d+", 'ball', text)
  5. print(word)
  6. word = re.sub(rf"\b(?:{'|'.join(map(re.escape, list1))})\d+\b", 'ball', text)
  7. print(word)
  8.  
Success #stdin #stdout 0.03s 9496KB
stdin
Standard input is empty
stdout
the books are good ball
the books are good ball