Pig Latin help me with regex

Pig Latin help me with regex


Tell us what’s happening:
I’m working on the pig latin problem and need help with Regex. If this is the wrong way to approach this problem, please redirect me.
when testing for Regex it returns true or false, right? so if I’m looking for the first instance of a vowel, is there a way I could test where it would give me the index on split where the Regex was met. also I forgot how to test split for the regex1. If I could find the index of where the first vowel occurs, I can use 2 slices of str and concat them with the ‘ay’ to get the correct answer.

Your code so far

function translatePigLatin(str) {
  let split = [...str];
  let regex1 = /a|i|e|o|u|y/;
  let firstVowel = [firstA, firstE, firstI, firstO, firstU];
  if (str.startsWith('a') || str.startsWith('e') || str.startsWith('i') || str.startsWith('o') || str.startsWith('u') || str.startsWith('y')) {
    return str + "way";
  } else{
    return str;


Your browser information:

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

Link to the challenge:


https://regexr.com/ that is reg clickable constructor you see immediately the reactions on the highlighted text
Yeah, that depends of test function. test is boolean match return

var s = 'Please yes\nmake my day!';
// Returns null
// Returns ["yes\nmake my day"]
var str = '#foo#';
var regex = /foo/y;

regex.lastIndex = 1;
regex.test(str); // true
regex.lastIndex = 5;
regex.test(str); // false (lastIndex is taken into account with sticky flag)
regex.lastIndex; // 0 (reset after match failure)
var text = 'Some text\nAnd some more\r\nAnd yet\rThis is the end';
var lines = text.split(/\r\n|\r|\n/);
console.log(lines); // logs [ 'Some text', 'And some more', 'And yet', 'This is the end' ]