英文:
regex query for filenames with multiple numbers at the beginning of the filename
问题
我正在尝试创建一个正则表达式查询。我需要这个正则表达式查询来从一个目录中提取文件名。
我将通过一个bash/shell脚本来运行这个正则表达式查询。
重要的是只能找到文件名开头有多个“文章编号”的文件,例如:123456_654321_test_testing-tags1-tags2.jpg
文件名可以包含下划线和连字符作为分隔符。
文件扩展名如下 = (jpg|tif|zip|mp4|psd|eps|flv|mov|png|mp3|bnl|pdf)
到目前为止,我已经通过一个正则表达式测试工具创建了以下正则表达式查询,但它不像我想象的那样工作。我真的不太理解它是如何使用捕获组的。
([[:digit:]]{2,})+([_])+([[:alnum:]]{3,})+
英文:
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,})+
答案1
得分: 2
你可以使用以下内容:
\d+_\d+[\w-]*\.(?:jpg|tif|zip|mp4|psd|eps|flv|mov|png|mp3|bnl|pdf)
英文:
You can use the following.
\d+_\d+[\w-]*\.(?:jpg|tif|zip|mp4|psd|eps|flv|mov|png|mp3|bnl|pdf)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论