fork download
  1. import re
  2. texts = ['But seeing them playing to seven- and eight-year-olds is beautiful', 'The country was in the uproar of pre- and then post-independence civil war but the mood here is most often joyous']
  3. rx = r''
  4. for text in texts:
  5. print( re.sub(r'- (and|to|or)((?: [^ -]+?){1,2})-(.+?)( |$|\n)', '-\\3 \\1\\2-\\3\\4', text) )
Success #stdin #stdout 0.02s 9652KB
stdin
Standard input is empty
stdout
But seeing them playing to seven-year-olds and eight-year-olds is beautiful
The country was in the uproar of pre-independence and then post-independence civil war but the mood here is most often joyous