Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to extract the number from the following line:
- - - - - - - - - - - - - - - - - - - - Frame 1 - - -
Any ideas?

Replies are listed 'Best First'.
Re: Simple regex needed
by fruiture (Curate) on Mar 20, 2003 at 19:58 UTC
      He didn't specify whether the number is single digit, so this would be more safe:
      /(\d+)/
        I also forgot to mention that there are other numbers in the file.

        So I need to look through the file and key my hash by using the number from the format I posted earlier.

Re: Simple regex needed
by BrowserUk (Patriarch) on Mar 20, 2003 at 21:14 UTC

    Maybe?

    my $frameNo = $1 if $line =~ m[^- - - - - - - - - - - - - - - - - - - - Frame (\d+) - +- -$];

    Examine what is said, not who speaks.
    1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
    2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
    3) Any sufficiently advanced technology is indistinguishable from magic.
    Arthur C. Clarke.
Re: Simple regex needed
by awkmonk (Monk) on Mar 21, 2003 at 09:12 UTC

    You could try this:

     

    $line = "- - - - - - - - - - - - - - - - - - - - Frame 123 - - -"; $line =~ /^[- ]+Frame +(\d+)[ -]+/; print $1;
Re: Simple regex needed
by Vorlin (Beadle) on Mar 20, 2003 at 22:08 UTC
    Without looking too much into it, a fast Q&D would be as follows:

    # Test line $line = "------------------- Frame 1 ------"; # Parse it by changing all -, letters, and spaces into nothing $line =~ s/[\-|A-Z|a-z|\s+]//g; # Print the line which returns '1' or whatever number it might be print "$line\n";
    Hope this helps! There's more extravagant ways to do it but that works effectively to solve your situation.