Linux Common command-grep and regular expressions

Source: Internet
Author: User

Regular expression: REGular expression,regexp


Metacharacters

.: Matches any single character

Touch a file

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7F/B4/wKiom1cpn1fzagelAAAHYouJBOw881.png "title=" QQ picture 20160504150537.png "alt=" Wkiom1cpn1fzagelaaahyoujbow881.png "/>

Use grep on the Test.txt file to query ' a ' separately

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/7F/B2/wKioL1cpoJaSJGQSAAAL_Z3uj5Q079.png "title=" QQ picture 20160504150726.png "alt=" Wkiol1cpojasjgqsaaal_z3uj5q079.png "/>

Use '. '

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7F/B2/wKioL1cppvXjn2VTAAAQwQZpIio148.png "title=" QQ picture 20160504153501.png "alt=" Wkiol1cppvxjn2vtaaaqwqzpiio148.png "/>

End With ' A ', any one of the preceding characters, beginning with ' A ', followed by any character.

[]: matches any single character within the specified range

[^]: matches any single character outside the specified range

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7F/B2/wKioL1cpqOWA0KUgAAAfQg2D39E572.png "title=" QQ picture 20160504154312.png "alt=" Wkiol1cpqowa0kugaaafqg2d39e572.png "/>

Character Set:

Pure numerals [[:d igit:]] or [0-9]

lowercase letters [[: Lower:]] or [A-z]

uppercase [[: Upper:]] or [A-z]

Uppercase and lowercase letters [[: Alpha:]] or [a-za-z]

Number plus letter [[: Alnum:]] or [0-9a-za-z]

blank character [[: Space:]]

Non-whitespace characters [^[:space:]]

punctuation [[:p UNCT:]]


Number of matches (greedy mode-to match as many as possible):

*: Matches any of its preceding characters any time

\?: Match its preceding character 1 or 0 times

\{m\}: Matches the preceding character m times (exact match)

\{m,n\}: Matches the preceding character at least m times, up to N times


Location anchoring:

^: Anchor the beginning of the line, any content after this character must appear at the beginning of the line

$: Anchor line end, any content in front of the second character must appear at the end of the row

^$: Blank Line


\< or \b: Anchor word, any character following it must appear as the first word

\> or \b: anchors the ending, any character preceding it must appear as the tail of the word


Group:

\ (\): Subsequent references

\1: Refers to the first opening parenthesis and all the contents of the corresponding closing parenthesis

\2: Refers to the second opening parenthesis and all the contents of the corresponding closing parenthesis

This article is from the "rime" blog, please be sure to keep this source http://kinrey.blog.51cto.com/10492082/1770029

Linux Common command-grep and 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.