Wildcards and regular expressions
1. Wild-card patterns are generally used to match file names, which are parsed by the shell, and are generally used for find (file search), ls (directory), cp (Copy), mv (move), etc.
The common wildcards in shell are *
0 or more characters ?
Match any character~
Current user home directory~+
Current working directory~-
The previous working directory[list]
matches any single character in the list[^list]
matches any single character in the list
[0-9]
or [:digit:]
Match numbers 0-9
[az] or [:lower:] lowercase letters az match
< code>[AZ] or [:upper:]
uppercase letters AZ match[az][AZ]
or [:alpha: ]
Match any uppercase and lowercase letters[:alnum:]
Any number or letters[:blank:]
Horizontal blank characters
[:space:]
Horizontal or vertical blank characters[:punct:]
Punctuation marks[:print:]
can be Printing symbols[:cntrl:]
: Control (non-printing) characters[:graph:]
: Graphic characters[: xdigit:]
: Hexadecimal characters
Sometimes you don’t need to use it if you want wildcards to become ordinary characters, then you have to use transfer characters.
”Single quotation marks, all the internal Wildcards will be turned off.
” “Double quotation marks, only specific shell characters are allowed inside: $ is used for parameter substitution.
\ Backslash, also called escape, removes the special meaning of the following wildcards .
2. Regular expressions
Regular expressions are often used to search and replace text that conforms to a certain pattern (rule), such as sed, grep, etc. Some items of regular expressions are similar to wildcards. Please pay attention to the difference. ^
Start of line$
End of line.
Any single character[] code>Single character in square brackets
[^]
Except any single character in square brackets^[]
Use the characters in square brackets at the beginning of the line
[]$
end of the line with the characters in brackets*
The characters before the characters are not determined the number of repetitions\+
The characters before the characters are repeated Uncertain times more than once\?
The preceding character repeats 1 or 0 \
Escape character.*
Any length character\{n\}
The preceding character is repeated n times\{n,\}
The preceding character is repeated more than n times\{m,n\}
The preceding character Repeating between m times and n times [::] internal wildcards are basically the same as regular expressions.