使用可选的子表达式查找命令正则表达式

问题描述 投票:1回答:1

我有以下文件列表

file                        <-
file.2019041543764832       <-
file.2019041643764832       <-
file.2019041243764832
file.2019041143764832

我想找到所有带有file前缀的标记文件,并且可选地以日期20190415xxxxx20190416xxxxx为后缀

我尝试了以下但它不会产生任何输出。

find . -regex 'file(\.2019041(5|6)[0-9].*)?' -regextype egrep

我需要一些正确的正则表达式类型和正确的语法来帮助实现这一目标。

linux shell find
1个回答
0
投票
find . -regex './file\(.2019041\(5\|6\)[0-9]*\)?' -regextype egrep

要不就

find . -regex './file\(.2019041[56][0-9]*\)?'

(当使用find .时,我的find版本使用./作为前缀,所以我将其添加到正则表达式中。)

© www.soinside.com 2019 - 2024. All rights reserved.