Linux Regular Expressions and Regular Expressions

Source: Internet
Author: User

Linux Regular Expressions and Regular Expressions

Basic Regular Expression

^ The string to be searched by word starts with word

Grep-n "^ a" regex.txt find the row whose first character is a and output the row number


Word $ the string to be searched ends with word

Grep-n "a $" regex.txt searches for the rows ending with a and outputs the row number

Grep-n "^ $" regex.txt searches for empty rows and outputs row numbers


. Represents any single character, including Spaces

\ Escape characters
* Repeat zero to infinite first characters
[List] For example, p [abc] d matches pad, pbd, and pcd.

[^ List] is opposite to [list], excluding any


[N1-n2] For example: [0-9] or [a-z] or [A-Z] represents any one in the range

Grep-n "9 [0-9]" regex.txt matches 90, 91 ...... 99


The first character of \ {n, m \} is n to m, for example, a \ {3, 5 \} matches aaa, aaaa, or aaaaa.

Grep-n "go \ {1, 2 \} d" regex.txt matched string is good god


The first character of \ {n, \} must be at least n times.

Grep-n "go \ {2, \} d" regex.txt matched string is good goood gooood...

Extended Regular Expression

+ Repeat the previous RE character at least once

? 0 or 1 time before a RE character

| Or

() As a group in parentheses

() + Repeated Group

\<\< Line whose abc starts with abc

\> Abc \> rows ending with abc

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.