We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Day 7: Regular Expressions I
Day 7: Regular Expressions I
+ 0 comments After reading others posts, there seem to be much better ways to do this than what I hacked together.
see...
var re = /^[a].+[a]$|^[e].+[e]$|^[i].+[i]$|^[o].+$[o]|^[u].+$[u]/; /* * Do not remove the return statement */ return re;
+ 2 comments function regexVar() { let re = /^([aeiou]).+\1$/; return re; }
+ 1 comment function regexVar(s) { let re = /^([aeiou]).*\1$/i return re; }
+ 0 comments Hello everyone, I wrote this code:
const str = "abcdo" let strCase let RegExp = /a|e|i|o|u/ let firstLetterTest let lastLetterTest let firstLetter let lastLetter strCase = str.toLowerCase() firstLetter = strCase[0] lastLetter = strCase[-1] firstLetterTest = RegExp.test(firstLetter) lastLetterTest = RegExp.test(lastLetter) if(firstLetterTest === false ||lastLetterTest === false) { return console.log(false) } else { let re = strCase.startsWith(firstLetter) && strCase.endsWith(firstLetter) }
as a solution to the problem, of course I tried to adapt it by passing
str
as a parameter to the function and changing the name of the function's return variable. Thanks if anyone has solutions for improvements...
+ 0 comments 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$/; /* * Do not remove the return statement */ return re;
}
Load more conversations
Sort 165 Discussions, By:
Please Login in order to post a comment