Linux Regular Expressions--extensions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.