Linux Regular expressions

Source: Internet
Author: User

Character

Range of characters in a single character: [] [A-z]

Inverse character ^: [^ 0-9] not a number

Any character: '. ‘

Kinsoku characters: ^ $, ^root//note differs from [^], empty line represents ^$

Metacharacters and repeat settings:

character Combinations :

The representation of any string:. *

. Represents any one character, * represents more than one character, and the regular expression is the maximum range, which needs to be added to a smaller range according to the desired result.

Logical Representation :

| Logical OR

grep ' bin/\ (false\|true\) ' passwd

Example:

Match 2-3-bit numbers in the passwd file

This contains the number [0-9], repeat {,}, delimiter/b/b

Case 2:

Match 15-bit or 18-bit ID number (supported with X)

Because the first card number can not be 0, the last one with X, in the middle there are 13-16 duplicates, ^$ represents the first and the end

grep ' ^[1-9]\ ([0-9]\{13\}|[ 0-9]\{16\}\) [0-9xx]$ ' File

Case 3:

Match password (consisting of letters, numbers, underscores)

grep ' ^\w\+$ ' file

Summary chart:

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.