Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Simple regex needed

by Anonymous Monk
on Mar 20, 2003 at 19:55 UTC ( #244694=perlquestion: print w/ replies, xml ) Need Help??
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?

Comment on Simple regex needed
Download Code
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 (Pope) 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 Vorlin (Sexton) 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.
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;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://244694]
Approved by diotalevi
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (11)
As of 2014-10-31 21:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (225 votes), past polls