Linux Regular Expressions-expressions

Source: Internet
Author: User

You may be familiar with the expression of a calculator explanation. Take a look at the following arithmetic expression:
2+4
"2 plus 4" is made up of several constants or literals and an operator. The calculator program must be able to recognize, for example, "2" is a numeric constant and the plus sign represents an operator, and cannot be interpreted as a "+" character.

An expression tells the computer how to produce a result. Although what we really want is the result of "2+4", we can't simply tell the computer to return 6. We instruct the computer to evaluate an expression and return a value. An expression can be more complex than "2+4," in fact, it consists of several simple expressions, such as:
2+3*4

The calculator usually evaluates the expression from left to right. However, some operators have higher precedence than other operators, that is, they will be executed first. Therefore, the result of the above expression is 14 instead of 20, because the multiplication takes precedence over addition. Placing a simple expression in parentheses can change the priority, so "(2+3)" or "2 plus 3 and 4 times times" results in 20. Parentheses are symbols that instruct the calculator to change the order in which expressions are evaluated.

Instead, a regular expression describes a pattern or sequence of characters. String joins are the basic operation of each regular expression. That is, a pattern matches a sequence of adjacent characters. Take a look at the following regular expression:
ABE

Each literal character is a regular expression that matches only that individual character. This expression describes "B follows a, E follows B" or simply called "String Abe". The term "string" means that each character is typeface connected to the character in front of it. It is not necessary to describe a regular expression as consisting of a sequence of characters (beginners tend to consider it to be made up of higher-level cells, such as a word rather than a separate character). Regular expressions are case-sensitive, so "a" does not match "a".

A program that accepts regular expressions, such as grep, must first parse the syntax of the regular expression to produce a pattern. Then they read the input line by line and did not attempt to match the pattern. The input line is a string, and to see if the string matches the pattern, the program compares the first character of the string to the first character of the pattern. If a match is matched, the second character is compared. Whenever a match fails, it returns and starts the match again from the character following the character in the string.

Reference: http://www.linuxawk.com/communication/387.html

Linux Regular Expressions-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.