Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

regex query for filenames with multiple numbers at the beginning of the filename

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading