Day 7: Regular Expressions I (10 Days of Javascript)

Task:

Complete the function in the editor below by returning a RegExp object,re , that matches any string s that begins and ends with the same vowel. Recall that the English vowels are aeio, and u.

Constraints

  • The length of string s is >=3 .
  • String s consists of lowercase letters only (i.e., [a-z]).


Solution:

function regexVar() {
    /*
     * Declare a RegExp object variable named 're'
     * It must match a string that starts and ends with the same vowel (i.e., {a, e, i, o, u})
     */
    
    let re=/^([aeiou]).*\1$/i;
    /*
     * Do not remove the return statement
     */
    return re;
}

Leave a Reply