fork download
  1. import re
  2.  
  3. regex = r"(?<![a-zA-Z0-9])(t)es(t)(?![a-zA-Z0-9])"
  4.  
  5. test_str = ("test=y\n"
  6. "tes't\n"
  7. "test'\n"
  8. "test-y\n"
  9. "tes-ty\n"
  10. " test Test \n"
  11. "test\n"
  12. "abcdefg Test ... test are the best... some thing words @@$: HAHA TEST ONE REAL PLAYER!!! EXCELLENT! It's testy night")
  13.  
  14. subst = "\\1**\\2"
  15.  
  16. result = re.sub(regex, subst, test_str, 0, re.IGNORECASE)
  17.  
  18. if result:
  19. print (result)
  20.  
  21.  
  22.  
Success #stdin #stdout 0.04s 9992KB
stdin
Standard input is empty
stdout
t**t=y
tes't
t**t'
t**t-y
tes-ty
    t**t  T**t    
t**t
abcdefg  T**t ... t**t are the best... some thing words @@$: HAHA T**T ONE REAL PLAYER!!! EXCELLENT! It's testy night