Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Thank you in advance for answering my question, I have been searching all afternoon for the correct regex to use and I feel the need to elevate the issue.
I am searching through a series of files, the beginning of the filename is guaranteed to have the first 6 characters as A-Z, the next two characters will be any combo of A-Z,0-9. The following two characters are A-Z. It is these last two characters that I am trying to match. I am running into problems where I am matching characters accidentally from the first part of the filename. E.g. If if I were searching for TL, STTLWA02TL01_2011-10-05.00.00.00.txt would correctly match, STTLWA02HJ01_2011-10-05.00.00.00.txt would erroneously match.
So my question is: how can I match my desired characters after the 8 initial characters?
This regex is obviously insufficient, since if $prompt_host = "TL", it will match it anywhere in the filename.
#Populate @traffic_file_list while (my $file = readdir(DIR)) { if($file =~ $prompt_host) { push(@traffic_file_list, $file); } }
Thank you!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Regex matching after ASCII characters
by suaveant (Parson) on Oct 05, 2011 at 20:31 UTC | |
by Anonymous Monk on Oct 05, 2011 at 21:11 UTC | |
by elTriberium (Friar) on Oct 05, 2011 at 21:36 UTC | |
by Anonymous Monk on Oct 05, 2011 at 21:41 UTC | |
by AnomalousMonk (Archbishop) on Oct 05, 2011 at 22:18 UTC |