简体   繁体   English

使用正则表达式获取不带点的扩展名

[英]Get extension without dot using regex

I have the regex (.*)(\\.zip|\\.tar\\.gz) meaning I have two groups, the name ( first part) and the second one that's the extension.我有正则表达式(.*)(\\.zip|\\.tar\\.gz)意味着我有两个组,名称(第一部分)和第二个是扩展名。

I want to be able to get the second group either zip, tar, or tar.gz without the ., only the extension name, how I can do that using regex only, I am using Java and I don't want to do any substring.我希望能够获得第二组 zip、tar 或 tar.gz 没有 .,只有扩展名,我如何只使用正则表达式来做到这一点,我正在使用 Java,我不想做任何事情子串。

将点移到第二个捕获组之外。

(.*)\.(zip|tar(?:\.gz)?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM