Summary of usage of regular expressions in Linux

Source: Internet
Author: User

First: In Linux, the regular expression is for the content of the file. Check in the Shell's grep,sed, awk and other related commands.

Metacharacters of regular Expressions:

. : Represents any character

Number of characters anchor:

*: Indicates that * previous characters or patterns appear any time, including 0 times

? Said Before the characters appear 0 or one time, it should be noted that in Linux needs to be \?.

\{m,n\}: Indicates that the preceding character or pattern appears at least m times, up to N times

\{m,\}: Indicates that the characters preceding it appear at least m times

\{0,n\}: Indicates that the character preceding it appears at most n times

Location anchoring:

^: denotes the beginning of the character following it

$: Indicates the end of the character in front of it

^$: Indicates a matching blank line

Match words: (you need to be aware of the meaning of words.) Root is the word, R. T is not considered a word in Linuxshell)

\<word: Represents a word that matches the beginning of Word.

Word\>: Represents a word that matches the end of Word

\<word\>: Indicates that the word matches the complete word

Range Matching:

[0-9]: Indicates a matching number

[A-Z]: Indicates a matching lowercase letter

[A-Z]: indicates matching uppercase letters

[[:p UNCT:]]: Indicates matching punctuation

[[: Space:]]: Indicates matching whitespace characters

[[: Lower:]]: Indicates a matching lowercase letter

[[: Upper:]]: Indicates matching uppercase letters

[[: Alpha:]]: Indicates matching letters, not case-sensitive letters

[[:d Igit:]]: Indicates a matching number

[[: Alnum:]]: Indicates a matching number letter

It is important to note that range matching indicates that one character in a range can be matched. Reverse matching is also supported. [^[::]]





Summary of usage of regular expressions in Linux

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.