Linux Regular expressions

Source: Internet
Author: User

The simple understanding is:

A regular expression is a set of rules and methods for handling strings, handling strings in a behavioral unit, and by means of special symbolic assistance, we can quickly filter and replace certain characters.

For example: grep (Egrep), the Sed,awk command requires regular expression mates. Improve efficiency.

Operation and maintenance work, there will be a large number of access logs, error logs, big data. All require regular expressions. (Quickly filter what you need)

The regular expression has some characters that give it a specific meaning:

Basic Regular expression: BRE

1) ^can indicates that the line starts with can.

2) can$ indicates that the line ends with can. "^$" means empty lines, for example: Grep-v "^$" to remove empty lines.

3). Represents any one of the characters (only one).

4) \ Escape symbol, let the character with special identity, invalid. For example

5) * Repeat 0 or more of the preceding characters

". *" matches all characters

6) [] symbol for repeating special characters for character sets

7) [^] means non-[^can] means non-C or a or n content [^0-9] matches non-numeric

9) {N,m} repeats n to M before a repeating character a{n,m} General curly braces need to be escaped a\{n,m\} use Egrep to remove slash

{n,} repeats a minimum of n times the previous repeating character

{n} repeats n times the previous repeating character

Extended Regular expression: ERE

1) + indicates repetition of one or more preceding characters

2)? 0 or one character (pending detection)

3) | To find multiple conforming strings in a way or chkconfig--list | Grep-e "Network|sshd"

4) () find the "user group" string

The above is an example of grep. Most available Awk,sed,grep,egrep

Find regular expression in Linux man grep search regular

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.