RegEx:Basic Algorithm Scripting: Confirm the Ending

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.

Challenge: Confirm the Ending

Link to the challenge:

The code you posted passes the test for me.

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.

Ah, I see. Have you seen RegEx 101? It’s a very helpful tool for understanding how regular expressions work. :slight_smile:

1 Like

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 @nhcarrigan here:

I used a different tool, but it works the same.

1 Like