• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 71
  • Last Modified:

Perl search string, validation

I need a perl search string to validate filenames as I iterate through them.

The filenames should all:
Have 25 characters plus the extension (.xlsx), for example: TESTY_ClinicalQ_20171104.xlsx
First 5 characters: caps alphabetic
underscore
"ClinicalQ" just as it is (first character capital C, then lowercase "linical", then capital Q)
underscore
Then 8 numeric characters
.xlsx
0
msibley
Asked:
msibley
1 Solution
 
NorieVBA ExpertCommented:
Perhaps you could use this pattern.

m/^[A-Z]{5}_ClinicalQ_[0-9]{8}.xlsx/

For example.
$test = "TESTY_ClinicalQ_20171104.xlsx";

$check =$test=~m/^[A-Z]{5}_ClinicalQ_[0-9]{8}.xlsx/ ;

if($check){
    print("Match");
}
else
{
    print("No match");
}

Open in new window

0
 
msibleyAuthor Commented:
Another REGEX wizard to the rescue! Thanks!
0
 
tel2Commented:
And this part:
    [0-9]{8}
can be abbreviated to:
    \d{8}
1
 
ozoCommented:
And  
  .
should be
 \.
1
 
tel2Commented:
And you might like to put a $ near the end like:
    xlsx$/
if you want to ensure it matches nothing after that, like:
    TESTY_ClinicalQ_20171104.xlsx.old
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now