I'm trying to use this code to scrape a web page with regex in PowerShell:
$webClient = New-Object System.Net.WebClient
$data = $webClient.downloadstring($url)
$h1Tag = [regex] '(?i)(?<=<h1 class="mb-0 mb-lg-1 svelte-jcq9ad">)([\S\s]*?)(?=<\/h1>)'
$h1 = $h1Tag.Match($data).value.trim()
Sample text to search:
<div>
<h1 class="mb-0 mb-lg-1 svelte-jcq9ad">AdBlock — best ad blocker</h1>
<h2 class="mb-2 svelte-jcq9ad">Block ads and pop-ups on YouTube, Facebook, Twitch, and your favorite websites.</h2>
</div>
</div>
It correctly returns AdBlock - best ad blocker when I test the regex expression on a couple of regex test sites, but in PowerShell $h1 is always empty. What am I missing?
Edit: I updated $title to $h1 in my question. $title was a typo on my part - $h1 is what I should have said.