in reply to Simple regex with numbers

Try this:

/Results <b>[\d,]+ thru [\d,]<\/b> of\s+([\d,]+)/

Or, if this number will always be at the end of the line (save maybe for whitespace):

/([\d,]+)\s*$/

Updated: per Skeeve's correction, below, I escaped the / in </b>. (And not only didn't I downvote it, I upvoted it. Corrections: good.)

Replies are listed 'Best First'.
Re^2: Simple regex with numbers
by Skeeve (Parson) on Sep 29, 2004 at 20:29 UTC
    -- because you missed a \. Your RE won't work.

    Update: At -1 ;-) Someone can't stand criticism? The missing \ is in the closing bold-tag: You should have used <\/b> instead of </b>

    $\=~s;s*.*;q^|D9JYJ^^qq^\//\\\///^;ex;print
Re^2: Simple regex with numbers
by Anonymous Monk on Sep 29, 2004 at 20:40 UTC
    Actually, it turns out there mght be a new line after OF and before the last number. So there can be any number of spaces and new lines (which would explain why I can't get any of the examples to work).

    How can I make it also work for newlines?

      \s+ should match new lines, so skeeve's example should still work. Unless you are reading in from a file, and are only reading one line at a time, in which case you would need to slurp the entire file in and then use skeeve's example.

      May the Force be with you
        \s+ should only match new lines if you add the s modifier to the end of the regex.

        This is balls. Of course it is. I was thinking of '.'. Stupid me.
      Not as easy, but solvable without slurping in the whole file. I assume you read from <> to $_
      my $num; while (m#Results\s+<b>[\d,]+\s+thru\s+[\d,]+</b>\s+of\s+([\d,]+)?\s*$# +) { $num=$1; last if defined $1 or eof; $_.=<>; } # value, if any, in $num

      $\=~s;s*.*;q^|D9JYJ^^qq^\//\\\///^;ex;print