Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Regular Expressions 1

Status
Not open for further replies.

jmdc

MIS
Feb 2, 2001
19
0
0
US
$line = aaa_A43.bbb11_07172002_00.ab.err
@line = split(/[a-zA-Z_.]+/, $line);

This is what I get - 43 11 07172002 00
How can I make @line = "07172002"
Please Help.

 
Here is a rough stab at it.

Code:
#!perl
$line = 'aaa_A43.bbb11_07172002_00.ab.err';

if ($line =~ /\w+_\w+\.\w+_(\d+)_\d+\.\w+\.\w+/)
    {
    print "chunk: $1\n";
    }

You will likely need to adjust the regex to better suit your
case. 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
This worked thanks, Now for the next problem I put this into an array like I did above. How do I get rid of the space before the numbers?

-Justin
 
If the format of the string is always the same, try

#!/c:/perl/bin/perl.exe

# splitting a string on _

use diagnostics;
$line = 'aaa_A43.bbb11_07172002_00.ab.err';

(undef,undef,$wanted,undef) = split('_',$line);
print "$wanted\n";

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top