正则表达式查询文件名以多个数字开头的文件名

huangapple go评论68阅读模式
英文:

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)

huangapple
  • 本文由 发表于 2023年6月12日 16:28:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76454804.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定