Skip to main content
1 of 3
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (ES6), 66 bytes

s=>s.replace(o=/[a-z]+/gi,w=>o[s]>(o[n=w.length]=-~o[n])?0:s=n)&&s 

Try it online!

Arnauld
  • 205.5k
  • 21
  • 187
  • 670