Regular expression of the Linux--shell script

Source: Internet
Author: User
Tags character classes

First, the concept and characteristics of regular expressions:
A regular expression is a logical formula for a string operation, which is to make a "rule string" with a predefined set of characters and a combination of those specific characters.
This "rule string" is used to express a filtering logic for a string. Specify some special syntax to represent character classes, quantifier and positional relationships, and then use these special syntax and
The pass character represents a pattern together, which is the regular expression (Regular expressions).
Given a regular expression and another string, we can achieve the following purposes:
1. Whether the given string conforms to the filtering logic of the regular expression (called "match");
2. You can get the specific part we want from the string using a regular expression.
The characteristics of regular expressions:
1. Flexibility, logic and functionality are very strong;
2. Complex control of strings can be achieved quickly and in a very simple way.
3. For people who have just come into contact, it is more obscure and difficult to understand.
Since the regular expression is mainly applied to text, it is applied in various text editor situations, as small as the famous editor EditPlus, Big to
Large editors, such as Microsoft Word, Visual Studio, can use regular expressions to work with text content.
Two, the regular expression has three parts:

For example, find more than the [email protected] mode of the string (that is, mail address), requires X can be letters, numbers, underscores, decimal points, dashes, email

Each part of the address can have one or more x characters, such as [email protected], [email protected], etc., and of course, this mode is not necessarily a legitimate mail address,

But at least one preliminary screening can be done to filter out non-conforming strings like a.b, [email protected] and so on. For example, find all strings that match the yyy.yyy.yyy.yyy pattern (IP ground

Y is a 0~9 number, and each part of the IP address can have a Y character.

1. Character class

Character class (Character Class): X and Y in the previous example, they represent a character in a pattern, but the range of values is any of a class of characters.

eg

2, Quantity qualifier

Quantity Qualifier (quantifier): Each part of a mail address can have one or more x characters, and each part of an IP address can have 1-3 y characters

eg

3. Position Qualifier

Positional qualifiers (Anchor): Describes the positional relationships between various character classes and ordinary characters, such as three parts of a mail address, separated by a normal character @ and. Separated by four parts, with. Separate, each part can be used

Character class and number qualifier description. In order to represent positional relationships, the concept of positional qualifiers is required, as described below.

eg

4. Special characters

eg

Regular expression of the Linux--shell script

Related Article

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.