Powershell & regex, select value in html

Hi,

I have a added a class tag in a site, specifically to be able to catch it via regex.
This is the html tag which I'm trying to catch

Table class="AntivirusKPI" border=2 cellpadding=4 cellspacing=3>                  
    <TR align=center>
    <TD><B>Latest Engineversion</B></TD>
    <TD><B>Percentage compliant</B></TD>
      <TR><TD align=center>1.1.14405.2</TD><TD class="AvengineVersionCompliancy" bgcolor=lightgreen align=center>99% </TD></TR>
      </Table>

When I try to get it, I do not get any result with regex.

        $URl = 'http://mysite'
        $pattern='<table .*class=\s*"AntivirusKPI"[^>]*>(?:.|\n)+?</table>'
        $webclient = New-Object System.Net.WebClient
        $html = $webclient.DownloadString($url)
        $Regex = [Regex]::Matches($html, $pattern)
        $Regex.value

Note that I also would like to catch tags with <td class=... <tr class= ... etc.

Please advise.
J.
janhoedtAsked:
Who is Participating?
 
footechCommented:
In your example, you're not getting a match because of case-sensitivity.  Using [regex]::Matches is case-sensitive by default.  You need to use a mode modifier to change that.
$pattern = '(?i)<table .*class=\s*"AntivirusKPI"[^>]*>(?:.|\n)+?</table>'

Open in new window


Sorry, but it's not clear to me what other matches you want and output.  For that, it's best to provide a few input samples and the expected output for each.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.