in reply to Regex for files
If I understand your requirements, you mean:
# Should match: messages messages.1 messages.345 # should not match: messages.txt messages. messages123
If that's correct, I'll assume you know how to open a directory and read the files, so then inside that loop, just see if the filename matches the pattern you're looking for. This pattern looks for a filename starting with "messages" followed optionally by a . and any number of digits. The grouping parentheses around the dot and digits ensure that it will have both or neither.
if($filename =~ /^messages(\.\d+)?/ ){ # this one matches }
Aaron B.
Available for small or large Perl jobs and *nix system administration; see my home node.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex for files
by marinersk (Priest) on Apr 23, 2015 at 03:20 UTC | |
|
Re^2: Regex for files
by bmcquill (Initiate) on Apr 23, 2015 at 04:27 UTC | |
by SimonPratt (Friar) on Apr 23, 2015 at 05:59 UTC | |
by aaron_baugher (Curate) on Apr 23, 2015 at 10:31 UTC | |
by RonW (Parson) on Apr 24, 2015 at 00:48 UTC |