Why here storyRegex.test returns false?

Basically I don’t understand the difference between part one of the code and the second section. this is related to the Regular Expressions: Match Ending String Patterns

let theEnding = "This is a never ending story";
let storyRegex = /story$/;
storyRegex.test(theEnding);
// Returns true
let noEnding = "Sometimes a story will have to end";
storyRegex.test(noEnding);
// Returns false

Hello~!

The key here is the $ operator. Your storyRegex looks for the literal string “story”, but the $ says that “story” has to be at the end of the string you are testing. :slight_smile:

2 Likes

ok many thanks :smile: