Regular Expressions - Find Characters with Lazy Matching

Tell us what’s happening:

Describe your issue in detail here.

Your code so far

let text = "<h1>Winter is coming</h1>";
let myRegex = /<[a-z0-9]*?>/; // Change this line
let result = text.match(myRegex);

According to my little thinking and understanding of the regular expressions the [a-z0-9]* will omit the all the alphabets and numeric in the HTML tag preventing h1 between the <> from being executed or outputted on the console giving the same alternative solution to the problem…suggestions are highly welcomed feel free to correct my approach of the solution

Your browser information:

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

Challenge Information:

Regular Expressions - Find Characters with Lazy Matching

It’s the exact opposite. It will match the opening angle bracket and then any characters that match either a-z or 0-9, which h1 will definitely match, and then it will match the closing > bracket. So you don’t really need the ? after it to match the the opening <h1> tag in the string. But that sort of defeats the purpose of the challenge which is to use ? in the expression.

To pass this, you don’t want to change the .* in the original expression. The only thing you want to do is add a ? so that the expression limits itself to just matching the opening <h1>.

1 Like

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