fork(2) download
  1. import re
  2. rx = re.compile('''
  3. \(?
  4. ([*=])
  5. (\w+)
  6. \)?
  7. ''', re.VERBOSE)
  8.  
  9. string = "Word1 word2 =word3 *word4 word5= word6 word7* (*word8)"
  10. new_string = rx.sub(r'\2\1', string)
  11. print(new_string)
Success #stdin #stdout 0.02s 9992KB
stdin
Standard input is empty
stdout
Word1 word2 word3= word4* word5= word6 word7* word8*