正则表达式匹配vim交换文件和其他临时文件,如“* .swp”和swx

时间:2012-11-17 18:07:00

标签: regex

我有一个bash脚本,它使用inotifywait来复制在目录中创建的文件。

但它正在复制我不想要的vim临时文件。

E.g。如果我创建foo.txt并在vim中编辑它,我最终会得到一些/所有这些:

foo.txt~
.foo.txt.swp
.foo.txt.swx
4913

我正在尝试编写正则表达式来匹配这些,这是我到目前为止所做的:

'^\*\.sw??$'

我希望至少能匹配swp和swx文件,但事实并非如此。

2 个答案:

答案 0 :(得分:2)

^.+?\.sw.?$

<强>解释

^ Start of string
.+? - Matches any character 1 or more (non greedy)
\. - matches literal .
sw.? - Matches sw followed by 1 character
$ - End of string

答案 1 :(得分:1)

试试这个正则表达式

^.+\.sw[px]$