Regular Expressions - Find Characters with Lazy Matching

Tell us what’s happening:
Describe your issue in detail here.
why is this still working even tho I added 3 wildcard ( . ) in a row?
could anyone explain me?

Your code so far

let text = "<h1>Winter is coming</h1>";
let myRegex = /<...*?>/gi; // Change this line
let result = text.match(myRegex);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Regular Expressions - Find Characters with Lazy Matching

Link to the challenge:

1 Like

Hi @sudoromeo

Why you are using a g tag? ;D

You can read here more about it: mdn regex cheatsheet and use this tool to help you regex101; explains what your regex is doing.

I hope that helps. Happy coding!

Er… that’s was my mistake I thought the challange want the output to be like this

[ '<h1>', '</h1>' ]
1 Like

Thanks a lot for you resource also

Tbh I am still confused about this

The first two wild cards are asking for there to be at least two characters, so <h1>. The third wildcard has * which will match zero or more of the previous character, and ? will try and limit the amount of characters * finds to as few as possible. So that regex is looking for at least two characters, but the third or more character is optional, because there can be zero of them. That is why its also seeing </h1> with three characters, and it will also see <something else much longer>.

1 Like

Now I understand.
Thanks !

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.