Hey everyone I trying to write a regular expression that catches all headers and subheaders in html code here is what I have so far
let html = "<h1>This is a header</h1> hello there <h2>This is a subheader</h2>"
let headerRegex = /(<h[0-9]>.*?<\/h[0-9]>)+/;
console.log(html.match(headerRegex));
and the console output is the following.
/*
[ '<h1>This is a header</h1>',
'<h1>This is a header</h1>',
index: 0,
input: '<h1>This is a header</h1> hello there <h2>This is a subheader</h2>',
groups: undefined ]
*/
As you can see it captures the h1 header twice. I cannot figure out how I can get it to capture both headers completely while also ignoring the text inbetween them.
Any help would be appreciated. Thank you!