Regular expressions are divided into two categories: the basic Regular Expression (BRE) and the extended regular expression (ERE).
-
1,.: Matches any single character
3, [^] : Matches a single character outside the specified range
4, *: matches any number of characters preceding it
5, \?: matches its preceding 0 or 1 times
6, \+: Matches its previous 1 or more
7, \{m\}: Exact match m times
8, \{m,n\}: matches at least m times, up to N times
9,. *: matches any character of any length
10, ^: Beginning of line anchoring,
11, $: End of line anchoring
12, \<: First anchor (can also use \b)
13, \>: Suffix anchor (can also use \b)
14, ^$: matching blank lines
15, \ (\): used in conjunction with \ n (numbers) to match the number of repetitions of a single or multiple character combination
The meta-character meaning of the extended regular expression:
1.: Match any single character
2, []: matches a single character within the specified range
3, [^]: matches a single character outside the specified range
4, *: matches any number of characters preceding it
5,?: Match its front 0 or 1 times
6, +: match its front 1 or more
7, {m}: exact match m times
8, {M,n}: matches at least m times, up to N times
9. *: Matches any character of any length
10, ^: anchor at the beginning of the line,
11. $: End of line anchoring
12, \<: The first anchor (can also be used \b)
13, \>: Suffix anchor (can also use \b)
14. ^$: Match blank line
15, (): Used with \ n (n is a number) to match the number of repetitions of a single or multiple character combinations
16, |: Match | characters before or after the symbol
Three, the command that can match the regular expression is: (here only grep command)
1. Grep:grep matches the line of text with the basic regular expression.
Format: grep [OPTIONS] PATTERN [FILE ...]
grep [OPTIONS] [-E PATTERN |-f file] [FILE ...]
Options:
-e: Match with extended regular expressions (equivalent to egrep)
-F: Equivalent to Fgrep
-I: Ignore case when matching
-V: Show rows that do not match the pattern
-O: Show only rows that match
-Q: Silent mode
--color=auto: Highlighting matched characters
Iv. Examples:
1. Display the line in the/etc/passwd file ending with bash;
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/A0/wKioL1XpvMXRW1r7AAFWKzAqsgg613.jpg "/>
2. Display the two-digit or three-digit number in the/etc/passwd file;
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/A4/wKiom1XpuqDwkP4nAASQ1S22tFM225.jpg "/>
3. Display lines with ' LISTEN ' followed by 0, one or more whitespace characters in the ' Netstat-tan ' command result
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/A0/wKioL1XpvMWhd4NXAAHppO__WTA044.jpg "/>
4, add user Bash,testbash, basher and Nologin user (Nologin the user's shell is/sbin/nologin), and then find the/etc/passwd file in the user name with the shell name of the line;
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/A4/wKiom1XpuqGDsfimAAFiwupLWN0947.jpg "/>
5. Display the default shell and UID of root, CentOS or User1 user on the current system;
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/A0/wKioL1XpvMbgOpRwAAHVNv-A0Go860.jpg "/>
6, find a word in the/etc/rc.d/init.d/functions file (the middle of the word can be underlined) followed by a set of parentheses line
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/A4/wKiom1XpuqGTUWefAAN-J62E6js792.jpg "/>
7, use echo to output a path, and then egrep find its path base name;
Further: Use Egrep to remove its directory name
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/A0/wKioL1XpvMah0ChvAAEr1RZtAKY459.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/A4/wKiom1XpuqGCDhnDAAEmdg3Hyq8306.jpg "/>
8. Find out the number between 1-255 in the result of ifconfig command execution;
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/A0/wKioL1XpvMayEbxVAARbm0qYFM4715.jpg "/>
This article is from the "Summer Month" blog, please make sure to keep this source http://lkc0110.blog.51cto.com/3410558/1691441
Regular expression of Linux command rollup