I can't get the reult

Tell us what’s happening:

Your code so far


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

Challenge: Find Characters with Lazy Matching

Link to the challenge:

Hi,

first of all let me say that a lot less changes to the original code are needed.

The original code matches the whole string (blue):

image

In words, it does the following:
Match a string that

  • starts with an opening angle bracket
  • followed by any acceptable character(s)
  • of which there are zero or more of
  • and ends with a closing bracket

By default the star is “greedy”, meaning it will match the longest possible string that ends with “>”. It would also swallow this nonsense:

In this lesson we learned that the “?” character allows us to turn “greedy” matching into “lazy” matching, meaning it matches the smallest possible amount. We do this by putting it behind the thing we want a minimal amount of.

So if we apply that to our desired outcome, our description would change to:

Match a string that

  • starts with an opening angle bracket
  • followed by any acceptable character(s)
  • of which there are zero or more of
  • preferably the smallest possible amount
  • and ends with a closing bracket

I would suggest you try to solve it with the above hints first. If you need more help, here is another hint with a spoiler alert:

image

I like this site for fiddling with regex: https://regexr.com/