Regular Expression to match files in Perl

Hi Everybody!

I need some help with a regular expression in Perl that will match files named messages, but also files named message.1, message.2 and so on. So really I need one that will find messages and messages that might be followed by a period and a digit without matching other files like messages.txt.

Here is the regular expression that I have come up with:

 if($file =~ /messages[.][0-9]/)

Using the regular expression above I am able to match the messages.1, message.2 files, but it will not pick up messages without the period and digit on the end.

O'Reilly School Of Technology(University of Illinois), Urbana-Champaign, IL USA, Kelly Hoover, Linux/Unix 4: Scripting for Administrators Sed, Awk, and Perl "O'Reilly Media - Technology and Business Training"

Thanks!!!:smiley:

--Hax0rc1ph3r--

if($file =~ /messages([.][0-9])?/)
1 Like

bartus11,

Thank you, that works. Matches the messages.txt as well, so I just added in another regex to run the command that I want on the the matches from the first regex, but excludes the .txt from the end.

--Hax0rc1ph3r--