Use of Linux Regular Expressions and usage of basic commands grep, egrep, and fgrep

Source: Internet
Author: User

I. Regular Expressions

The use of a system is not only the installation, debugging, and maintenance of software, but also the optimization and reform of the existing environment, in linux, we always encounter many descriptions of parameters. Sometimes we need the answer given by the parameter itself. Sometimes we only need the final State result of the parameter.

Is a set of special or not very special string modes. Some metacharacters are used to indicate some wildcard meanings, which can be simply called regular expressions.

REGular EXPression: REGular EXPression, abbreviated as REGEXP

Metacharacters:

.: Match any single character

Number of matched characters (working in greedy mode, try to match as much as possible ):

*: Match any character before it.

A, B, AB, aab, acb, adb, amnb

A * B

. *: Match any character of any length

[]: Match any single character in the specified range

[^]: Match any single character out of the specified range

[: Digit:], [: lower:], [: upper:], [: punct:], [: space:], [: alpha:], [: alnum:]

\? : Match the first character once or 0

\ {M, n \}: match the first character at least m times, at most n times

\ {1, \} at least once

\ {0, 3 \} up to three times

Positioning:

^: Specifies the beginning of the line. Any content after this character must appear at the beginning of the line.

$: Specifies the end of the line. Any content after this character must appear at the end of the line.

^ $: Blank line

\ <Or \ B: the beginning of the anchor, and any character after it must appear as the first word

\> Or \ B: Specifies the end of a word. Any character before it must appear at the end of the word.

\ <Root \>: exact match with root

GROUP:

\(\)

\ (AB \) * AB can appear 0 times 1 times any time

Backward reference

\ 1: The first left brace and all the content contained in the corresponding right Brace

\ 2: The second left brace and all the content contained in the corresponding right brace

\ 3: the third left brace and all the content contained in the corresponding right Brace

Extended regular expression:

Character match:

.: Match any single character

[]: Match any single character in the specified range

[^]: Match any single character out of the specified range

Matching times:

*:

? : Match the first character 0 or once

+: Match the first character at least once.

{M, n}: match at least m times to n times

Positioning:

^: Specifies the beginning of the line. Any content after this character must appear at the beginning of the line.

$: Specifies the end of the line. Any content after this character must appear at the end of the line.

^ $: Blank line

\ <Or \ B: the beginning of the anchor, and any character after it must appear as the first word

\> Or \ B: Specifies the end of a word. Any character before it must appear at the end of the word.

\ <Root \>: exact match with root

GROUP:

(): Group

\ 1, \ 2, \ 3 ,...

Or

|: Or (a | abc a or abc)

  • 1
  • 2
  • Next Page

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.