Regular expressions are divided into two categories: the basic Regular Expression (BRE) and the extended regular expression (ERE).
- the meta-character meaning of the basic regular expression:
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 previous 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/M02/72/68/wKioL1XjKUXwSnr2AAFWKzAqsgg942.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/M02/72/6B/wKiom1XjJyjyc6dIAASQ1S22tFM578.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/M00/72/6B/wKiom1XjJyiw5KQHAAHppO__WTA655.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/M01/72/68/wKioL1XjKUbQd8brAAFiwupLWN0956.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/M01/72/6B/wKiom1XjJynwA3t9AAHVNv-A0Go715.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/M02/72/68/wKioL1XjKUbixgFgAAN-J62E6js075.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/M00/72/6B/wKiom1XjJymS7ueNAAEr1RZtAKY617.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/6B/wKiom1XjJymgKTk8AAEmdg3Hyq8724.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/M01/72/68/wKioL1XjKUfgrHrnAARbm0qYFM4276.jpg "/>
Regular expression of Linux command rollup