2016-05-17 17 views
0

爲什麼當文件存在時它什麼也不查找?或查找的正則表達式中的條件

find ./ -regex '.*(jar|war)'

+0

我很困惑,所以你說找到以**開頭的字符串,然後是任何帶有war或jar的字符串都附在字符串的末尾? – jgr208

+1

在這種特殊情況下,'-name'* [jw] ar''就足夠了。 –

回答

2

人發現信息有關的正則表達式支持的語法:

-regextype type 
     Changes the regular expression syntax understood by -regex and 
     -iregex tests which occur later on the command line. Currently- 
     implemented types are emacs (this is the default), posix-awk, 
     posix-basic, posix-egrep and posix-extended. 

這工作:

$ find . -regextype egrep -regex '(.*jar)|(.*war)' 

爲了避免使用-regextype變化表達到emacs正則表達式:

$ find . -regex '.*\(jar\|war\)' 
+0

謝謝。你是對的 – viavad

+1

我添加了emacs正則表達式到答案,所以你不必擔心-regextype查找參數。基本上,在emacs表達式中,必須有反斜槓轉義括號和管道字符。 – kbulgrien