Tell us what’s happening:
Just curious to see other ways to write this.
I triedlet Regex = /target$/; to no avail. Tried to define the target parameter as a new variable. Any ideas?
Your code so far
function confirmEnding(str, target) {
let re = new RegExp(target + "$", "i");
return re.test(str);
}
confirmEnding("Bastian", "n");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36.
I posted the 2nd Solution. its identical to mine except for the regex syntax. /target/g returned true for all matches but when i added $ it would not search only the ending. just trying to learn the notation for the furure.
Thats interesting. I’ve been thinking I need to just read a glossary of terms. I don’t know what code is baked into the cake of the editor and what is JS. I still don’t know what a regular expression is.
A regular expression is a pattern used to match characters of a string. This is particularly useful when you want to verify if the word given is a certain word, or maybe a certain username. I haven’t found a lot of use on it, but it’s a really powerful JavaScript method.
Learn more about RegEx (Regular Expression) here:
As of practicing it, you can use the website provided by @Naomi here: