I am trying to create a regex query. I need the regex query to extract filenames from a directory.
I will run the regex query via a bash/shell script
It is important that only files are found which have several "article numbers" at the beginning of the file. e. g.: 123456_654321_test_testing-tags1-tags2.jpg
The file name may contain underscores and hyphens as separators.
The file extensions are as follows = (jpg|tif|zip|mp4|psd|eps|flv|mov|png|mp3|bnl|pdf)
So far, I have created the following regex query via a regex tester, but this does not work as I thought it would. I don’t really understand how it works with the capturing groups.
([[:digit:]]{2,})+([_])+([[:alnum:]]{3,})+
>Solution :
You can use the following.
\d+_\d+[\w-]*\.(?:jpg|tif|zip|mp4|psd|eps|flv|mov|png|mp3|bnl|pdf)