Regex Lazy Matching

Tell us what’s happening:
Describe your issue in detail here.

how the result comes “h1” instead of only “h” ?

Your code so far


let text = "<h1>Winter is coming</h1>";
let myRegex = /<.*?>/; // 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/99.0.4844.74 Safari/537.36

Challenge: Find Characters with Lazy Matching

Link to the challenge:

Hey!
For /<.*?>/ regex:
. matches any character (except for line terminators)

*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)

That’s why it’ll return h1 instead of just h

I use this website to write regex :smiley: https://regex101.com/

thank you, I got it.

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