1. [] 塞選出任何符合這裏面放的字的項目
例如:
- Cat.png
- Bat.png
- Rat.png
- car.png
- list.png
- mom.jpg
- cat.jpg
If you wanted to match only the title cased files in this list, you could use the pattern [CBR]at
.
This would return the result:
- Cat.png
- Bat.png
- Rat.png
2.
[!CBR]at
這個則是和上面的相反:
- car.png
- list.png
- mom.jpg
- cat.jpg
3.Backslashes are used to remove the special meaning of single characters '?'
, '*'
, and '['
, so that they can be used in patterns.
4.Asterisks (*)
The most common wildcard that you'll see is the asterisk. This character is used in many ways but is mainly used to match any number of characters (like parts of a string).
The three main use cases of asterisks that I've seen used are:
*
- On Linux, will match everything except slashes. On Windows, it will avoid matching backslashes as well as slashes.**
- Recursively matches zero or more directories that fall under the current directory.*(pattern_list)
- Only matches if zero or one occurrence of any pattern is included in the pattern-list above
These use cases can also be used in conjunction with each other! For example, to find all Markdown files recursively that end with .md
, the pattern would be **/*.md
Note: *.md
would only return the file paths in the current directory, which is why we append **/
at the beginning.
5.
Something important that I want to note is that while wildcard patterns are similar to regex patterns, they are not explicitly the same for two main reasons:- Globs are meant to match filenames rather than text
- Not all conventions are the same between them (example:
*
means zero or more copies of the same thing in regex)
沒有留言:
張貼留言