我有一个bash脚本,它使用inotifywait来复制在目录中创建的文件。
但它正在复制我不想要的vim临时文件。
E.g。如果我创建foo.txt
并在vim中编辑它,我最终会得到一些/所有这些:
foo.txt~
.foo.txt.swp
.foo.txt.swx
4913
我正在尝试编写正则表达式来匹配这些,这是我到目前为止所做的:
'^\*\.sw??$'
我希望至少能匹配swp和swx文件,但事实并非如此。
答案 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]$