Pig latin question over $

I am wondering what does the $1$2 do? My understanding is that they are

  **Your code so far**
function translatePigLatin(str) {
return str
.replace(/^[aeiou]\w*/ , '$&way')
.replace(/(^[^aeiou]+)(\w*)/, '$2$1ay')

  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Pig Latin

Link to the challenge:

$1 refers to the 1st capture group represented by (^[^aeiou]+) and $2 refers to the 2nd capture group represented by (\w*). So whatever gets matched in those respective capture groups is used in the replacement value '$2$1ay'

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.