Tell us what’s happening:
May be I am going about this the wrong way, I am trying to use a regex to search for the target string at the end of the string. I attempted to use the target as a changeable variable. Only it is not working as intended. Your code so far
function confirmEnding(str, target) {
let myRegex = /`${target}`$/
let result = myRegex.test(str)
return result;
}
confirmEnding("Bastian", "n");
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36.
Yes, you can. A template literal resolves to a string. You can convert strings to regex. You build your string (with a template literal if you want) and then convert it to regex with the method shown in the links above.