So, I understand the syntax for the wildcard period, but I just don’t get what it actually does. In the example code below, the boolean value returns true for all alternative words (run, sun, bun etc) with or without the wildcard period (i.e the tests all pass except: using the wildcard period.) Can anyone provide a realworld example of using the wildcard effectively over just testing “un” by itself?
let exampleStr = "Let's have fun with regular expressions!";
let unRegex = /.un/; // Change this line
let result = unRegex.test(exampleStr);
console.log(result);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
Yeah, the difference is that /un/ will match any string with “un” in it, but /.un/ will only match it if there is a character in from of it, so it won’t match “un” or “under”.
Perhaps the instructions could make that more clear and also test for that. You can make a suggestion in the Contributor’s room if you want.