fork(1) 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(text):
  5. if 'founder' in text:
  6. return 'CEO'
  7. elif text.isdigit() and len(text) == 9:
  8. return 'NUM'
  9. else:
  10. return text
  11.  
  12. print(replace_em("Some founder here"))
  13. print(replace_em("123456789"))
  14. print(replace_em("Some other text"))
Success #stdin #stdout 0.04s 9576KB
stdin
Standard input is empty
stdout
CEO
NUM
Some other text