I. Extending the regular expression
The string representations of regular expressions are divided into basic regular expressions and extended regular expressions according to different rigor. Extended Regular Expressions In addition to some simple set of string processing, you can also do a group string processing.
The difference and the meta-character of the base regular expression
1, the number of matches
+ Match the preceding character at least once
{m} matches M-Times
{m,n} at least m times, up to N times
{m,} at least m times
{0,n} up to n times
2. Grouping
() grouping
| Or for example: AC|BC is AB or BC
Third, Egrep
EGRP equivalent to GREP-E using an extended regular expression to build the pattern
Iv. Extended Regular Expression exercises
1. Find the Netstat-tan command execution results with "LISTEN" or "stablished" end of the line
Netstat-tan | grep--color-e "(listen| Established) [[: space:]]*]
Key point for this topic: CAT-E the string before viewing the Terminator
2. Find the integer 1-255 under the ifconfig command
Ifconfig | grep--color=auto-e
"\< ([1-9]|[ 1-9][0-9]| [1] [0-9] [0-9]| [2] [0-4] [0-9]| [2] [5] [0-5]) \> "
Key points of this topic: Group anchor Word first ending
3. Match the IP address in the real sense
Ifconfig | grep--color=auto-e
"(\< ([1-9]|[ 1-9][0-9]| [1] [0-9] [0-9]| [2] [0-4] [0-9]| [2] [5] [0-5]) \>)\.) {3} (\< ([1-9]|[ 1-9][0-9]| [1] [0-9] [0-9]| [2] [0-4] [0-9]| [2] [5] [0-5]) \>) "
The key point of this topic: \. The regular expression has a special meaning, with the escape character to remove its special meaning
Linux Regular Expressions--extensions