I am trying to write a regex for the bash find command in OS X that will be able to return a sequence of TV episodes in a directory. The titles of the files are in the format "Show Name SXXEYY Episode title.mp4"
Various regex testers give me good results when I use the expression
Firefly S02E(0[8-9]|1[0-3]).*\.mp4
to filter the list, for example:
Firefly S02E07 Heat of Two Suns.mp4
Firefly S02E08 Mal's Wedding.mp4
Firefly S02E09 Inara's Secret.mp4
Firefly S02E10 Burn the Land (1).mp4
Firefly S02E11 Boil the Sea (2).mp4
Firefly S02E12 Rules of Misbehaviour.mp4
Firefly S02E13 The Strawberry Heist.mp4
Firefly S02E14 Monsoon Season.mp4
Firefly S02E15 Book's Next Chapter.mp4
when I just want to return episodes 8 through 13. When I use this in a find command, however, the results are disappointing.
find -E . -regex 'Firefly S02E(0[8-9]|1[0-3]).*\.mp4'
returns nothing.
What is the error I'm making? This has me baffled at the moment.
-regex
requires the pattern to match the whole path, not just the filename part. You need to put .*/
at the beginning of the pattern, to match the directory part of the path.
find -E . -regex '.*/Firefly S02E(0[8-9]|1[0-3]).*\.mp4'