Find Characters with Lazy Matching

Find Characters with Lazy Matching
0

#1

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:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/find-characters-with-lazy-matching


#2

@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?


#3

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


#4

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


#5

Try this if you’re stuck

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

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

witch is the best answer to this question?


#7

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?