Find Characters with Lazy Matching

Find Characters with Lazy Matching


please help me :relieved:

Your code so far

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

Your browser information:

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

Link to the challenge:


@arrbxr This sentence in the challenge is important:

Fix the regex /<.*>/ to return the HTML…

Generally, when it says fix it means one only needs to make a small change. Does that help?


idk about him but it helped me a lot :slight_smile: Thanks!


I was confused about this but this solved /<h1.*?>/


Try this if you’re stuck

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

let myRegex = /<[h1.]*?>/;
let myRegex = /<[h1]*?>/;
let myRegex = /<h1>?/;

witch is the best answer to this question?


This is my solution:
let myRegex = /<h1*?>/;

Basically you’re finding the shortest route from “<h1” to the next “>”. Without the question mark, it would find the longest route to the next “>” which would return the whole variable.

Can someone confirm my explanation/answer?