首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >需要regex命令来提取带有2个点(.)的完整文件名

需要regex命令来提取带有2个点(.)的完整文件名
EN

Stack Overflow用户
提问于 2021-04-10 14:38:29
回答 1查看 76关注 0票数 2

我在提取带有两个点(.)的完整文件名时遇到问题。

虽然下面的命令是有效的,但我需要在regex中没有asterix的替代解决方案。有没有人可以帮助我在替代的regex命令提取完整的文件名没有asterix?

代码语言:javascript
复制
(ABC_A.*\.)+.*  

以下是我正在尝试匹配的文件名:

代码语言:javascript
复制
ABC_A_CommunityRollover_Autocreate_Community.12345678-1.out
ABC_A_CommunityRollover_Autocreate_Community.88345678-1.out
ABC_A_CommunityRollover_Autocreate_Community.99945678-1.out
EN

回答 1

Stack Overflow用户

发布于 2021-05-13 05:08:23

TL;DR:

代码语言:javascript
复制
^ABC_A(?:[^.]+\.){2}[^.]+$

说明

代码语言:javascript
复制
--------------------------------------------------------------------------------
  ^                        the beginning of the string
--------------------------------------------------------------------------------
  ABC_A                    'ABC_A'
--------------------------------------------------------------------------------
  (?:                      group, but do not capture (2 times):
--------------------------------------------------------------------------------
    [^.]+                    any character except: '.' (1 or more
                             times (matching the most amount
                             possible))
--------------------------------------------------------------------------------
    \.                       '.'
--------------------------------------------------------------------------------
  ){2}                     end of grouping
--------------------------------------------------------------------------------
  [^.]+                    any character except: '.' (1 or more times
                           (matching the most amount possible))
--------------------------------------------------------------------------------
  $                        before an optional \n, and the end of the
                           string
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67031505

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档