Match Anything with Wildcard Period

I dont understand, everything is working, but not this two :
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.”

is it a bug ?

Your code so far


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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Firefox/60.0.

Link to the challenge:

1 Like

Remove the g flag.

2 Likes

Hello everyone!

While removing the “g” flag indeed works, could anyone expand why it can’t be there? I mean it seems to me even more correct to have it in order to “catch” all the “*un” words and when I tried it in my program it gave me a TRUE result…

let exampleStr = "The sun is out today.";
let unRegex = /.un/gi; // Change this line
let result = unRegex.test(exampleStr);

console.log(result);

Thanks a lot for help here!

Dan

The reason why it will appear to work when you test it on your own, but fail to pass the tests is because for the tests your expression is used multiple times to test multiple inputs.

This StackOverflow thread explains it pretty well: