Match Anything with Wildcard Period # 22

Sometimes we won't (or don't need to) know the exact characters in our patterns. Thinking of all words that match, say, a misspelling would take a long time. Luckily, we can save time using the wildcard character(.)

The wildcard character. will match any one character. The wildcard is also called dot and period. You can use the wildcard character just like any other character in the regex. For example, if you wanted to match hug, huh, hut, and hum, you can use the regex /hu./ to match all four words.

let humStr = "I'll hum a song";
let hugStr = "Bear hug";
let huRegex = /hu./;
huRegex.test(humStr);
huRegex.test(hugStr);

Both of these test calls would return true.


Post a Comment

Previous Post Next Post