Skip to main content
3 of 3
Commonmark migration

JavaScript (ES6), 25 bytes

s=>/(.+?)\1*$/.exec(s)[1]

Try it online!

Regular expression

   +-------> 1st (and only) capturing group: 1 or more character(s), non greedily
   |   +---> reference to the capturing group, repeated 0 to N times
  _|_  | +-> end of string
 /   \/ \|
/(.+?)\1*$/
Arnauld
  • 197.7k
  • 20
  • 179
  • 650