Perl Monk, Perl Meditation | |
PerlMonks |
Re: Checking number in file nameby space_monk (Chaplain) |
on May 19, 2013 at 15:07 UTC ( [id://1034223]=note: print w/replies, xml ) | Need Help?? |
Whilst (\w+) will match on digits also, you're probably better using ^(\d+); you're also better putting the start marker outside the brackets. Note also that "\w" also accepts "_" characters, so if you know a filename is going to be a certain pattern you are best tying it down as tightly as possible. Note that also you probably need to look at greedy and non-greedy matching - that initial (\w+) may be getting all the characters I admit regexs still manage to beat me occasionally and one way of building up patterns is to start at the simplest and incrementally make it more complex.
You can also use glob to find all files that match a certain pattern.
If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)
In Section
Seekers of Perl Wisdom
|
|