Complaining is just an act of incompetence, without it. --Brother Ma, it's always a positive energy.
Regular Expressions:
Understanding: A pattern that is pieced together by a meta-character and a normal character, summed up by the corresponding "formula" based on certain characteristics of the target character or string
Function: can be used for file lookup, pattern matching, etc.
Character Matching:
.: Matches any single character
[]: matches any single character within the specified range
[^]: matches any single character outside the specified range.
Number of matches:
*: The characters on the left appear any time
. *: Any character of any length
\?: the character on its left appears 0 times or 1 this
\+: The character on the left side appears 1 or more times
\{m\}: Exact match to its left character appears m this
\{m,n\}: Matches its left character at least m times, up to N times
Location anchoring:
^: Anchoring the beginning of the line
$: Anchor Line End
\<: Anchor Word first
\>: Anchor ending
^$: Matches blank lines, including lines with only spaces and tabs!!!
\ (\): group. This feeling is relatively tall yet. In the grouping mode, the characters that are matched during a match are memorized temporarily by grep (saved to the built-in variable \1,\2 ... Medium), therefore
\1: Refers to the first parenthesis from left to right and the corresponding bracketed contents
Practice as follows:
Find the lines in the/proc/meminfo file that begin with uppercase s or lowercase s:
Displays users and default shells whose default shell is non-/sbin/nologin in the/etc/passwd file
Displays one or two digits in the/etc/passwd file (not including three-bit and measurements-digits)
Displays lines in the/boot/grub/grub.conf file that begin with at least one white space character followed by the I character
Find information about users on your system whose user name and default shell are the same
D
This article is from the "Ops Dog" blog, make sure to keep this source http://yunweigou.blog.51cto.com/6299641/1627427
Regular Expressions of Linux