I. Regular Expressions
The use of a system is not only the installation, debugging, and maintenance of software, but also the optimization and reform of the existing environment, in linux, we always encounter many descriptions of parameters. Sometimes we need the answer given by the parameter itself. Sometimes we only need the final State result of the parameter.
Is a set of special or not very special string modes. Some metacharacters are used to indicate some wildcard meanings, which can be simply called regular expressions.
REGular EXPression: REGular EXPression, abbreviated as REGEXP
Metacharacters:
.: Match any single character
Number of matched characters (working in greedy mode, try to match as much as possible ):
*: Match any character before it.
A, B, AB, aab, acb, adb, amnb
A * B
. *: Match any character of any length
[]: Match any single character in the specified range
[^]: Match any single character out of the specified range
[: Digit:], [: lower:], [: upper:], [: punct:], [: space:], [: alpha:], [: alnum:]
\? : Match the first character once or 0
\ {M, n \}: match the first character at least m times, at most n times
\ {1, \} at least once
\ {0, 3 \} up to three times
Positioning:
^: Specifies the beginning of the line. Any content after this character must appear at the beginning of the line.
$: Specifies the end of the line. Any content after this character must appear at the end of the line.
^ $: Blank line
\ <Or \ B: the beginning of the anchor, and any character after it must appear as the first word
\> Or \ B: Specifies the end of a word. Any character before it must appear at the end of the word.
\ <Root \>: exact match with root
GROUP:
\(\)
\ (AB \) * AB can appear 0 times 1 times any time
Backward reference
\ 1: The first left brace and all the content contained in the corresponding right Brace
\ 2: The second left brace and all the content contained in the corresponding right brace
\ 3: the third left brace and all the content contained in the corresponding right Brace
Extended regular expression:
Character match:
.: Match any single character
[]: Match any single character in the specified range
[^]: Match any single character out of the specified range
Matching times:
*:
? : Match the first character 0 or once
+: Match the first character at least once.
{M, n}: match at least m times to n times
Positioning:
^: Specifies the beginning of the line. Any content after this character must appear at the beginning of the line.
$: Specifies the end of the line. Any content after this character must appear at the end of the line.
^ $: Blank line
\ <Or \ B: the beginning of the anchor, and any character after it must appear as the first word
\> Or \ B: Specifies the end of a word. Any character before it must appear at the end of the word.
\ <Root \>: exact match with root
GROUP:
(): Group
\ 1, \ 2, \ 3 ,...
Or
|: Or (a | abc a or abc)