fork download
  1. import re
  2.  
  3. string = '\t \r\nFoo\t Fooo\t Dog\t Foo\t \r\n\r\n'
  4. result = re.sub(
  5. '^[\r\n\t]+|[\r\n\t]+$|([\r\n\t]+)',
  6. lambda x: '|' if x.group(1) else '',
  7. string
  8. )
  9. print(result)
Success #stdin #stdout 0.03s 9448KB
stdin
Standard input is empty
stdout
 |Foo| Fooo| Dog| Foo|