Skip to main content
added 1 character in body
Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

JavaScript (ES6), 8181 74 bytes

f=
s=>s.replace(/(?=(.+)\1)/g,(_,m)=>(n=m=>r=m[r.length)>l&&(l=n,r=m)length]?m:r,l=0r='')&&s.replace(r,'')
<input oninput=o.textContent=f(this.value,r='')><pre id=o>

TheEdit: Saved 7 bytes by stealing @Arnauld's ,r=''m[r.length] prevents the function crashing on invalid inputtrick.

JavaScript (ES6), 81 bytes

f=
s=>s.replace(/(?=(.+)\1)/g,(_,m)=>(n=m.length)>l&&(l=n,r=m),l=0)&&s.replace(r,'')
<input oninput=o.textContent=f(this.value,r='')><pre id=o>

The ,r='' prevents the function crashing on invalid input.

JavaScript (ES6), 81 74 bytes

f=
s=>s.replace(/(?=(.+)\1)/g,(_,m)=>r=m[r.length]?m:r,r='')&&s.replace(r,'')
<input oninput=o.textContent=f(this.value)><pre id=o>

Edit: Saved 7 bytes by stealing @Arnauld's m[r.length] trick.

Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

JavaScript (ES6), 81 bytes

f=
s=>s.replace(/(?=(.+)\1)/g,(_,m)=>(n=m.length)>l&&(l=n,r=m),l=0)&&s.replace(r,'')
<input oninput=o.textContent=f(this.value,r='')><pre id=o>

The ,r='' prevents the function crashing on invalid input.