in general, there are three parts, each of which are: character class , quantifier, position qualifier.
Specifies that some special syntax denotes character class, number
Volume qualifiers and positional relationships, and then use these special syntax together with ordinary characters to represent a pattern, which is the regular form (Regular expression).
We take a
Let's start with a sample example. If you have a file that contains an IP address, there are some that are not qualified. Please find out the qualified IP address. I don't think I know
Then the expression of the person must be considered a good stranger, I take a loop to achieve, I have been asked this question before, but also want to take the loop to complete. Write a letter
The number to implement this lookup function is really not easy. And there is no guarantee of correctness.
This is the time for the advent of the form. Here's a regular I wrote.
An expression:
This is not the moment to think it is very wonderful. I felt it, too, in the five "IP" addresses above. Just one satisfying request, we have a
command to find out, is not immediately attracted to live. So let's start with a discussion of the form.
1. Character classes:
They represent a character in a pattern, but the range of values is arbitrary in a class of characters.
Common character classes such as the following:
I wrote some simple code to verify the above character class
Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center ">
2. Quantity qualifier
The number qualifier indicates the number of occurrences of the character class to help with pattern matching, such as the following common quantifier characters:
The test code I wrote for example is the following:
My use is CentOS, do not know carefully you found no. There is a syntax that does not support that is: {, M}.
Z This is possible on other Linux.
For example Ubantu, I think this problem should be caused by different platform differences.
I was able to test it under the Ubantu platform of my classmate, this can guarantee.
3. Position Qualifier
As the name implies, the position qualifier uses the position of the qualifying character class. For example, let's take the IP address. The IP address is divided into four parts. Between each of the two sections
separated by '. ', and each section is able to describe the character class and the number qualifier.
Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center ">
Special characters:
1. \ this character is used for transfer, the above example used in the "." To use the "\" to transfer, or can not be interpreted
2. | ' | ' can be used to connect a two-character expression
3. () ' () ' can be a part of a whole, then we can operate on the overall
here the regular expression of the grammar is basically finished, the following examples of the use of the tools used in a simple introduction, grep tools believe that everyone knows
, the Linux platform's own tools, the introduction of grep I cite the introduction of Sogou Encyclopedia:grep is a powerful text search tool . It can use positive
the expression search for text and print out the matching lines. The grep family of Unix contains grep, egrep, and Fgrep.
These return values make it possible to perform a
self-initiated text processing. I used the Egrep tool in the example above. is the extension of grep, a lot of other ways to use this tool and the above introduction
Some of the inadequate places you can go to the encyclopedia to find out, in fact, some of the more advanced tools also support this expression. I'll be in the knot.
The blog is again introduced.
I personally think that the rote of these characters is inappropriate. We should learn the form through constant practice, so that the ability to achieve good performance
Fruit. When we forget, we are able to look at the usefulness of these forms of modules, and finally we hope to have some help for you.
Shell Scripting Learning Notes (normal form)