fnmatch 檔名的正則匹配

2021-08-21 01:22:51 字數 920 閱讀 9107

**:

fnmatch:int fnmatch(const char *pattern, const char *string, int flags);

man中是這麼寫道:the  fnmatch()  function checks whether the string argument matches the pattern argument, which is a shell wildcard pattern. 就是判斷字串是不是符合pattern所指的結構。

如果這個標誌設定了,處理反斜槓為普通字元,而不是轉義字元。

fnm_pathname

如果這個標誌設定了,string 裡的斜槓只匹配 pattern 裡的斜槓,它不能匹配星號(*)或問號(?)元字元,也不能匹配包含斜槓的中括號表示式()。

fnm_period

如果這個標誌設定了,string 裡的起始點號必須匹配 pattern 裡的點號。乙個點號被認為是起始點號,如果它是string 第乙個字元,或者如果同時設定了 fnm_pathname,緊跟在斜槓後面的點號。

fnm_file_name

這是 fnm_pathname 的 gnu 同義語。

fnm_leading_dir

如果這個標誌(gnu 擴充套件)設定了,模式必須匹配跟隨在斜槓之後的 string 的初始片斷。這個標誌主要是給 glibc 內部使用並且只在一定條件下實現。

fnm_casefold

如果這個標誌(gnu 擴充套件)設定了,模式匹配忽略大小寫。

#include #include #include #include int main(int argc, char *argv)

else if(ret == fnm_nomatch)else

}closedir(dir);

}}

Javascript正則匹配檔名和檔案字尾

去除字串前後空格 string.prototype.trim function 11位手機號格式化 function telformat tel,space d d 1 space 2 space 3 獲取路徑檔案資訊 檔名 字尾名 var path c users sungang desktop ...

linux檔名匹配

匹配檔名中的任何字串,包括空字串。匹配檔名中的任何單個字元。匹配 中所包含的任何字元。匹配 中非感嘆號!之後的字元。如 s s開頭的所有字串 s s結尾的所有字串 s?以s為倒數第二個字元的字串 0 9 所有以數字的字元 a,b a或者b 0 9 不是數字的字元 ls user a n sh 列出 ...

linux檔名匹配(萬用字元使用)

當在使用命令行時,有很多時間都用來查詢你所需要的檔案,如ls find等。s h e l l提供了一套完整的字串模式匹配規則,或者稱之為元字元,當s h e l l遇到上述字元時,就會把它們當作特殊字元,而不是檔名中的普通字元,這樣使用者就可以用它們來匹配相應的檔名,我理解這可以稱為萬用字元。萬用字...