需要正则表达式命令来提取具有 2 个点.的完整文件名

问题描述

我在提取包含 2 个点 (.) 的完整文件名时遇到问题。
虽然下面的命令正在工作,但我需要一个在正则表达式中没有星号的替代解决方案。任何人都可以帮助我使用备用正则表达式命令来提取不带星号的完整文件名吗?

(ABC_A.*\.)+.*  

这是我要匹配的文件名:

ABC_A_CommunityRollover_autocreate_Community.12345678-1.out
ABC_A_CommunityRollover_autocreate_Community.88345678-1.out
ABC_A_CommunityRollover_autocreate_Community.99945678-1.out

解决方法

TL;博士:

^ABC_A(?:[^.]+\.){2}[^.]+$

Live Demo

说明

--------------------------------------------------------------------------------
  ^                        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