Pig Latin - word with no vowels

Tell us what’s happening:
I’m stumped. I seem to be geting the correct results, even for a word without a vowel but I can’t pass the check.
any suggestions?

Your code so far


function translatePigLatin(str) {
 
  let regEx = /([aeiou]*)/i // match vowels
  let regEx2 = /(^[aeiou]+)(.+)/i;
  let regEx3 = /([^aeiou]*)(.+)/i
  // console.log(str.match(regEx));
  if (str.match(regEx2) === null || str.match(regEx) === null){ // first char ! a vowel
  return str.replace(regEx3, '$2$1ay');
  }
  return str.concat('way');
}

translatePigLatin("consonant");
console.log(translatePigLatin("california"));
console.log(translatePigLatin("glove"));
console.log(translatePigLatin("algorithm"));
console.log(translatePigLatin("why"));

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin

It is not passing all the tests, i.e. “prgnct” => returns “tprgncay”. It moves the ending “t” to the front because of the ending quantifier + in regex3. This quantifier should be * because if it is + it requires for the 2nd subexpression to be matched, so it backtracks even though it doesn’t have to because the whole word consists of consonants and the first subexpression can match it fully. So, since it backtracks one character at a time, the 2nd subexpression is matched to the “t” in my example, and it moves the “t” to the front.

I hope this helps.

Thank you, that did help.