[英]Regex pattern for filename with date
I have files with name "data_2021_03_v1.0.zip" in server.我在服务器中有名为“data_2021_03_v1.0.zip”的文件。 When I tried using "data.*(ZIP|zip)" regex.It is loading all files starting with data string.
当我尝试使用“data.*(ZIP|zip)”正则表达式时,它正在加载所有以数据字符串开头的文件。 I want files containing only data(exactmatch-no extra words along with it) in filename.
我想要文件名中只包含数据(完全匹配-没有额外的单词)的文件。
Ex: It is loading files with name "data_abc_efg_19-01-v2.0.zip" along with original file.例如:它正在加载名称为“data_abc_efg_19-01-v2.0.zip”的文件以及原始文件。 Can someone help to construct a regex pattern for above file format
有人可以帮助为上述文件格式构建正则表达式模式吗
Looking at the sample I am assuming that all you need is: data_<number>_<version_info>.查看示例,我假设您只需要:data_<number>_<version_info>。
Here is a regex for this:这是一个正则表达式:
data(_?\d)*(_v\d)?\.?\d\.(zip|ZIP)
You can make the pattern more specific您可以使模式更具体
\bdata_\d{4}_\d{2}_v\d+(?:\.\d+)*\.(?:ZIP|zip)\b
\bdata_
A word boundary to prevent a partial match, then match data_
\bdata_
防止部分匹配的单词边界,然后匹配data_
\d{4}_\d{2}_v
Match 4 digits _
2 digits _v
\d{4}_\d{2}_v
匹配 4 位_
2 位_v
\d+(?:\.\d+)*
Match 1+ digits and optionally repeat a .
\d+(?:\.\d+)*
匹配 1+ 个数字并可选择重复 a .
and 1+ digits\.(?:ZIP|zip)
Match either .zip
or .ZIP
\.(?:ZIP|zip)
匹配.zip
或.ZIP
\b
A word boundary \b
一个词的边界You could make the pattern case insensitive, but then you would also match DATA for example您可以使模式不区分大小写,但是您也可以匹配 DATA 例如
(?i)\bdata_\d{4}_\d{2}_v\d+(?:\.\d+)*\.zip\b
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.