Linux Regular expressions

Source: Internet
Author: User

Regular Expressions Reguler expression , REGEXP

Basic REGEXP: base Regular Expression

Extended REGEXP: extending regular Expressions

1.grep [options] mode [files] commands for filtering text using the basic regular expression pattern

-I ignores case

--color plus Color

-V Reverse lookup

-O displays only strings that are matched by the pattern

- e support for extended regular expressions

-A N: shows not only the matches but also the n rows below the line

-B N: Shows not only the matches but also the n rows above the line

-C N: Displays not only matches but also rows above and below the line of n

Pattern rules

. match any single character

[] matches any single character within the specified range

[^] matches any single character outside the specified range

[: Space:]: white space character

[:p Unot:]: punctuation

[: Lower:]: lowercase letters

[: Upper:]: size Letter

[: Alpha:]: uppercase and lowercase letters

[:d igit:]: number

[: Alnum:]: numbers and uppercase and lowercase letters

Two when used [[]]

Number of Matches

*: matches its preceding character any time

\? : matches the preceding character 1 or 0 times

\{m,n\} matches the preceding characters at least m times up to n times

By default in greedy mode, match as many characters as possible

Position lock

^ Rivet Header, must start with its trailing character

$ Rivet Line End

^$ Blank Line

\<: Any character following it must appear as a word header or can be used \b

\>: Any character in front of it must appear as a trailing word or can be used \b

Group

\(\)

\1 referencing the first group

\2 referencing a second group

...


Extending regular Expressions

GREP-E = Egrep to use an extended regular expression

Character Matching:

. usage is the same as the basic regular

[]

[^]

Number of Matches

*:

?:

+: match the characters in front of it at least 1 times

{M,n} The usage is the same as the basic regular, but does not add \

Position Lock: Usage is the same as the basic

^

$

\<

\>

Group:

(): Group

\1 \2 \3 ...

Or

| : OR

Fgrep: Fast Search does not support regular expressions


This article is from the "Mr.zhu-Technology Exchange" blog, please be sure to keep this source http://bjishu.blog.51cto.com/7481301/1699663

Linux Regular expressions

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.