Regular expression collation of Linux text processing

Source: Internet
Author: User
Tags control characters printable characters uppercase letter alphanumeric characters

^ Beginning of the line.


$ end of line.


. Any character other than the line break.


* The preceding character repeats 0 to several times.


. * Used to match all characters.


[] Define a set of characters that match any one by one characters in the group (note!) Just one within the group! )


[^] Performs an inverse operation on characters within a character group (without any one by one characters in a group)


^[] The line at the beginning of the string within the group.


^[^] A line that begins with a string that is not within a group.


[A-z] matches a lowercase letter.


[A-z] matches an uppercase letter.


[A-z] matches a lowercase and uppercase letter.


[0-9] matches a number of 0-9.


\< Match Word Header

\> match end of Word

(The definition of a word in the regular is that it is separated by a space or other special character, and successive strings are treated as words.) )


Expansion of the Regular:

? Previous characters match 0 or 1


+ Previous characters match 1 or more


| logic or, for example abc|def ABC or DEF


() parentheses, for grouping, example: A (Bc|de) f

The meaning is ABCF or adef.


S{n} s was repeated n times.


S{n,} s repeats at least n times, even more times.


S{n,m} s repeats at least n times and repeats at most m times.


POSIX-defined character classifications:


[: Alnum:] Alphanumeric characters.

Match range is [a-za-z0-9]

[: Alpha:] Alphabetic characters.

Match range is [a-za-z]

[: Blank:] Space or tab characters.

Match range is space and TAB key

[: Cntrl:] Control characters.

Match control keys such as ^m to press CTRL + V and press ENTER to output

[:d Igit:] Numeric characters.

Match all numbers [0-9]

[: Graph:] Characters that is both printable and visible. (A space is print-

Able, but no visible, while a-a is both.)

Matching all visible characters without spaces and tabs is all the symbols you can see with your eyes on your keyboard in a text document

[: Lower:] lower-case alphabetic characters.

lowercase [A-z]

[:p rint:] Printable characters (characters that is not control characters.)

Match all visible characters including spaces and tab

All symbols that can be printed on the paper

[:p UNCT:] Punctuation characters (characters, digits, con-

Trol characters, or space characters).

Special input symbol +-=) (*&^%$#@!~ ' |\ "' {}[]:;? />.<,

Note that it does not contain spaces and tab

This set is not equal to ^[a-za-z0-9]

[: Space:] Space characters (such as space, tab, and FormFeed, to name a few).

[: Upper:] Upper-case alphabetic characters.

uppercase [A-z]

[: Xdigit:] Characters that is hexadecimal digits.

16 binary number [0-f]

How to use:

[[email protected] ~]# grep--color ' [[: Alnum:]] '/etc/passwd


This article is from the "Rebirth" blog, make sure to keep this source http://suhaozhi.blog.51cto.com/7272298/1909379

Regular expression collation of Linux text processing

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.