Note: The regular expression is a matching string, and the wildcard is a matching file name
Regular expression rules:
* Previous character matches 0 or more times
. Match any character except the line break
^ matches the beginning of the line. For example: ^hello matches lines that begin with Hello
$ Match Line End
[] matches any one of the characters specified in the brackets, matching only one character
[^] matches any character except the characters in brackets, matching only one character
\ escape character, for cancellation, to cancel the meaning of the special symbol
\{n\} indicates that the preceding characters appear exactly n times. For example: [0-9]\{4\} means matching 4 digits
\{n,\} indicates that the preceding character appears not less than n times. For example: [0-9]\{2,\} represents two digits and above
\{n,m\} indicates that the preceding characters appear at least n times, up to M times. For example: [a-z]\{6,8\} matches lowercase letters from 6 to 8 bits
Example: (A.txt is to find the file used)
grep "A *" a.txt #表示匹配文件a all content in. txt, including blank lines
grep "aa*" A.txt #表示匹配至少含一个a的行
grep "aaa*" A.txt #表示匹配至少含两个aa的行
grep "s.. D "A.txt #表示匹配s和d之间有两个字符的行
grep "S.*d" A.txt #表示匹配只要包含s和d就行
grep "\.$" A.txt #表示匹配以. The end of the line, where the backslash is to be canceled. Special meaning
Linux Regular expressions