Cannot read property '0' of nul

Following code showing "Cannot read property '0' of null"

 function translatePigLatin(str) {
 let x=["a",'e','i','o','u','A','E','I','O','U'];
 //let x=["aeiouAEIOU"];
 let regex=/[aeiou]/ig;
 var vowelIndice = str.indexOf(str.match(regex)[0]);
 if (str[0].match(regex)) {
    return str + 'way';

return str.match(regex)===null?str+"ay":str.substr(vowelIndice) + str.substr(0, vowelIndice) + 'ay';

Where am i wrong..?

You might be missing a closing bracket } at the end of your function. Try to add } after your outer return statement.

still it is showing same error

If str.match returns null, then it does not have any indices to access