REGEX expression usage

Hello:)

let text = "<h1>Winter is coming</h1>";
let myRegex = /<.*?>/; 
let result = text.match(myRegex);

I am struggling to understand the myRegex part of the code. I know those symbols one by one: . - wildcard; *- match character; ?- lazy matching
How comes that they give a result <h1>?
Can sb explain it pls?

What result are you seeing, and what result are you expecting?

That is the result if I console.log it out.

[ '<h1>',
  index: 0,
  input: '<h1>Winter is coming</h1>',
  groups: undefined ]

The regex captures only <h1> with those three symbols.
thanks

Hi there,

I like this regex tester because it provides a detailed explanation on the upper right side of the screen. So, if you plug in your test string and your regex (without the //), hopefully you’ll be able to understand why the h1 element was selected based on this tool’s explanation.

If you’d like to dig into regex a little deeper, the Full Stack Developer curriculum (JavaScript > RegEx) has great coverage in the lectures.

1 Like

Thanks for your advice:)

and is that not what you expect?