The regular expression string represents different types of expressions with different degrees of rigor: Basic Regular Expressions and extended regular expressions,
Next let's take a look at the basic regular expression:
Frequently Used symbols
[; Alnum:] represents 0-9 A-Z A-Z
[: Alpha:] represents a-Z A-Z
[: Lower:] indicates a-z
[: Upper:] indicates a A-Z
[: Digit:] indicates 0-9
Before learning regular expressions, it is necessary to understand the use of grep.
Grep [-A] [-B] [-- color = auto] 'query string 'filename'
A can be followed by a number, which means after. In addition to listing this row, N industries will be listed later.
B can be followed by a number, which is the meaning of before. In addition to listing and modifying rows, the preceding n industries are listed.
Now, let's give an exercise regular expression in English:
"Open Source" is a good mechanic to develop programs.
Apple is my favorite food.
Football game is not use feet only.
This dress doesn' t fit me.
However, this dress is about $3183 dollars. ^ m
GNU is free air not free beer. ^ m
Her hair is very beauty. ^ m
I can't finish the test. ^ m
Oh! The soup taste good. ^ m
Motorcycle is cheap than car.
This window is clear.
The symbol '*' is represented as start.
Oh! My God!
The GD software is a library for drafting programs. ^ m
You are the best is mean you are the No. 1.
The world I like dog.
Google is the best tools for search keyword.
Goooooogle yes!
Go! Go! Let's go.
# I am vbird
(Download from laruence's private dish)
There are 22 rows in this file, and the bottom line is blank. Now let's start with a case study.
Case 1: Search for rows containing
Case 2
Search for rows that do not contain
Case 3: rows containing the 'or''
Case 4: Search for rows containing test and taste,
Careful analysis requirements: Both test and taste contain t s and T
Case 5: locate the rows that are not g in front of OO
Case 6: Search for rows containing numbers
Case 7: Search for rows starting with lowercase letters
Case 8: the end of the trip is the decimal point.
Case 10 search for blank lines
In the expression
. Represents any character
* Indicates that the previous character has been repeated for 0 or multiple times.
Then. * indicates that any character is repeated for any number of times, including 0
Explain the last knowledge point to limit the continuous character range {}
Case 11: Search for rows with 2-5 consecutive 0 rows
Basic Regular Expression characters
^ Word: string to be queried at the beginning of a row
Wrod $ string to be checked at the end of the row
* Repeat 0 to Infinitely multiple first characters
[LIST] Find the desired characters from the character set and
[^ List] returns a string range from the characters in the set.
\ {M, N \} consecutive m to N previous characters