I need to find first names and last names inside H1 element such as,
<h1>Kalani Doe</h1>
But not one that has the word "Profile" in it, such as,
<h1>Kalani Doe | Profile</h1>
I know I need to use ?! but I can’t get around to understand how to combine positive and negative.
I tried this,
(<h1>(.+?)<\/h1>)(?!<h1>(.+?)Profile<\/h1>)
But it didn’t work.
>Solution :
you can use negative Lookbehind (?<!chars)
const str = `<h1>Kalani Doe</h1>
<h1>Kalani Doe | Profile</h1>
<h1>John Doe</h1>`;
let m = str.match(/<h1>.*(?<!Profile)<\/h1>/gm)
console.log(m);