in reply to Re: Simple regex with numbers
in thread Simple regex with numbers

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?

Replies are listed 'Best First'.
Re^3: Simple regex with numbers
by JediWizard (Deacon) on Sep 29, 2004 at 20:46 UTC

    \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.
Re^3: Simple regex with numbers
by Skeeve (Parson) on Sep 29, 2004 at 21:27 UTC
    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