RegEx help

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 5 years, 8 months ago.

  • Author
    Posts
  • #5106

    by marco.shaw at 2012-09-12 19:53:44

    I'm trying to access the following URL:
    $uri="http://www.lotterycanada.com/lotto-max/2012-01-06"

    If you try to hit that address, I'm interested in the section that might appear directly in the middle of your screen:

    Winners Prize
    0 $16,000,000.00

    I want to capture the Winners value and also the Prize value. For starters, I was just trying to capture the Prize value.

    I've tried this, which doesn't seem to work at all, and I get the whole contents of the page returned:
    invoke-webrequest $uri|select-string "\d{1,3}\,\d{3,}\,\d{3,}\.\d{2,}" -AllMatches

    I've also tried this, but -match only seems to provide the first match, and it doesn't find the value I'm looking for, but something more at the start of the page where there's another regex match:
    invoke-webrequest $uri|where{$_ -match "\d{1,3}\,\d{3,}\,\d{3,}\.\d{2,}"}
    $matches

    Any ideas/clues on what I could try?

    by Klaas at 2012-09-13 02:02:51

    Hi Marco

    I got a bit further with:
    (invoke-webrequest $uri).tostring().split(" ").split("< ").split(">") |select-string "\d{1,3}\,\d{3,}\,\d{3,}\.\d{2,}" -AllMatches

    Probably not very generic or reusable, but on this page it does the trick. The HtmlWebResponseObject is converted to one string. I don't know if there are other methods to split it into multiple strings.

    Klaas

You must be logged in to reply to this topic.