in reply to Checking number in file name
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.
1) $filename =~ /^(\d+)_/ 2) $filename =~ /^(\d+)_(\d+)/ 3) $filename =~ /^(\d+)_(\d+)_(\w+)/ ....
You can also use glob to find all files that match a certain pattern.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Checking number in file name
by Anonymous Monk on May 19, 2013 at 15:38 UTC |