Use regEx to replace characters in a string

PHOTO EMBED

Sat Sep 23 2023 15:01:45 GMT+0000 (Coordinated Universal Time)

Saved by @Paloma

function pigIt(str){
  return str.replace(/(\w)(\w*)(\s|$)/g, "\$2\$1ay\$3")
}
content_copyCOPY

The parenthesis create groups witch are referred to thanks to $+group number in the second parameter

https://www.codewars.com/kata/520b9d2ad5c005041100000f/solutions/javascript