First, regular expression
A, the basic regular expression
| Meta character |
Description |
| . |
Match any single character |
| * |
Match any of its preceding characters any time |
| .* |
Any character of any length |
| [] |
Matches any single character within the specified range |
| [^] |
Matches any single character outside the specified range |
| [: Lower:] |
lowercase letters |
| [: Upper:] |
Capital |
| [: Alpha:] |
All letters |
| [:d Igit:] |
Digital |
| [: Alnum:] |
All numbers and letters |
| [:p UNCT:] |
Punctuation |
| [: Space:] |
White space characters |
| \? |
Match its preceding character 1 or 0 times |
| {M,n} |
Matches the preceding character at least m times, up to N times |
| ^ |
Riveting the beginning of the line, any content after this character must appear at the beginning of the line |
| $ |
Rivet line end, any content in front of this character must appear at the end of the row |
| ^$ |
Represents a blank line |
| \< or \b |
The first of the riveting word, any character after it must appear as the header of the word |
| \> or \b |
A riveting ending, any character in front of which must appear as the tail of a word |
| () |
Group |
| (AB) * |
AB as a whole, can appear any time |
| (AB). *\1 |
Refers to the first opening parenthesis and all the contents of the corresponding closing parenthesis |
| (AB). *\2 |
Refers to the second opening parenthesis and all the contents of the corresponding closing parenthesis |
B. Extend the entire expression
| . |
match any single character |
| [] |
Matches any single character within the specified range |
| [^] |
Matches any single character outside the specified range |
| * |
Match its preceding characters any time |
| ? |
Match its first character 0 or 1 times |
| + |
Match its preceding character at least 1 times, similar to the basic regular expression {1,} |
| {M,n} |
Matches the preceding character at least m times, up to N times |
| ^ |
Header |
| $ |
End of Line |
| \< or \b |
Word Head |
| \> or \b |
Ending |
C, examples
CP one copy of/etc/passwd file to/tmp
Linux Shell Example (ii)