Match Anything with Wildcard Period - use of 'g' flag fails some tests

Tell us what’s happening:
When I use the global flag, it fails two of the tests (Your regex unRegex should match “sun” in “The sun is out today.” & Your regex unRegex should match “pun” in “Seven days without a pun makes one weak.”) and I can’t figure out why this is happening.

Your code so far


let exampleStr = "Let's have fun with regular expressions!";
let unRegex = /.un/i; // Change this line
let result = unRegex.test(exampleStr);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/match-anything-with-wildcard-period

It should work, there is probably a bug with this challenge.

In Windows with Google Chrome and FireFox in the debugger console, using the g flag with the regex matches the input strings.

I’d say that there is a bug with the challenge when you’re trying to use the g flag. Your code passes the tests without it.

No bug. Just run the following in your browser’s console.

let exampleStr = "Let's have fun with regular expressions!";
let unRegex = /.un/ig; // Change this line
console.log(unRegex.test("Let us go on a run."));  // displays true
console.log(unRegex.test("The sun is out today.")); // displays false

This phenomenon is best explained in the following Stack Overflow thread.

That is evil. I can see the result flipping from true to false to true when running only unRegex.test(“The sun is out today.”) Nice catch.