fork download
  1. import re
  2. #regex1 : if the text contains the word "founder", replace all text by CEO
  3. #regex 2 : if the text contains 9 digit number , replace it with NUM
  4. def replace_em(m):
  5. return 'NUM' if m.group(1) else 'CEO'
  6.  
  7. regex = re.compile(r'(?s)^([0-9]{9})$|.*founder.*')
  8.  
  9. print(re.sub(regex, replace_em, "Some founder here"))
  10. print(re.sub(regex, replace_em, "123456789"))
  11. print(re.sub(regex, replace_em, "Some other text"))
Success #stdin #stdout 0.04s 9552KB
stdin
Standard input is empty
stdout
CEO
NUM
Some other text