Character
Range of characters in a single character: [] [A-z]
Inverse character ^: [^ 0-9] not a number
Any character: '. ‘
Kinsoku characters: ^ $, ^root//note differs from [^], empty line represents ^$
Metacharacters and repeat settings:
character Combinations :
The representation of any string:. *
. Represents any one character, * represents more than one character, and the regular expression is the maximum range, which needs to be added to a smaller range according to the desired result.
Logical Representation :
| Logical OR
grep ' bin/\ (false\|true\) ' passwd
Example:
Match 2-3-bit numbers in the passwd file
This contains the number [0-9], repeat {,}, delimiter/b/b
Case 2:
Match 15-bit or 18-bit ID number (supported with X)
Because the first card number can not be 0, the last one with X, in the middle there are 13-16 duplicates, ^$ represents the first and the end
grep ' ^[1-9]\ ([0-9]\{13\}|[ 0-9]\{16\}\) [0-9xx]$ ' File
Case 3:
Match password (consisting of letters, numbers, underscores)
grep ' ^\w\+$ ' file
Summary chart:
Linux Regular expressions