Basic Regular expression (supports shell tools such as Grep,sed,awk)
* 0 or more of the ordinary characters in front of the * character
. Match any character
^ matches the beginning of the line, or the following character is non
$ Match Line End
[] Match Character Set
\ escape character, masking the special meaning of a meta-character
\<\> Exact Match symbol
\{n\} matches the preceding character n times
\{n,\} matches the preceding character at least n times
\{n,m\} matches the preceding character appears n~m times
Note: The symbol * must be preceded by at least two characters (when there is no character after the symbol *) or must be preceded by at least one character (when there is at least one word after the symbol *) makes sense
Symbols. Must have characters at the same time to make sense.
[] Before use
1. Symbol * 0 or more of the ordinary characters in front of the * character
Example Hel*o
Hel*o can be Heo,helo,hello,helllo can appear 0 to infinite times
2. Characters. Match any character
Example. 7
.7 First This is two characters, where the next character is 7, and the previous character is a character that can be output on any keyboard
... 7 This is 4 characters, the last one is 7, the preceding 3 characters are the characters that can be output on any keyboard
Comprehensive
Hel*o. This represents any one character behind the Heo.
Helo any one character behind
Any one character after Hello
Hel.*o This means that starting with Hel, any character at the end of O can match
3. Symbol ^ matches the beginning of the line, or the following character is non-
Example ^cloud
^cloud the character that represents the beginning of the line is a cloud row that will be matched
Comprehensive
^h.*o indicates that the beginning of the line h must begin with an O ending with any character
4. Symbol $ match Line end
Example hel$ indicates that a HEL must be used as the end of the line
Synthetic ^h.*o$ indicates that an O is the beginning of the line with H as any character in the middle of the end
^$ represents an empty
The ^hjo$ represents the first h of the line, and the end of the line is the O-middle for J to match, meaning that only hjo will be matched.
5. Symbol [] Match character Set
Example 1. Poor lifting
[123456789] means matching any number
Example of the use of 2.-(range)
[1-9] means matching any number
[A-z] matches any lowercase letter
[A-z] matches any uppercase letter
[^]
^ in [] means to take the reverse
example [^b-d] means matching all characters that are not between B and D
Comprehensive
[A-za-z] [a-za-z]* matches all the English words
[A-za-z1-9] [a-za-z1-9]* matches all English words and numbers
6. Symbol \ Escape character, shielding the special meaning of a meta-character
\* matches * characters,
7. Symbol \<\> exact match symbol
Shielding <>
Example \<the\> matches the word and does not contain the word or line
8.\{\} series symbols match the number of occurrences of the preceding character
\{n\} matches the preceding character n times
Example
a\{4\} matching AAAA
\{n,\} matches the preceding character at least n times
Example
A\{2,\} matches Aa,aaa,aaaa ...
\{n,m\} matches the preceding character appears n~m times
A{2,4\} match Aa,aaa,aaaa
Comprehensive
[A-z]\{5\} matches 5 lowercase letters
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Extended Regular expression (supports tools such as Awk,perl)
? Match 0 or 1 of the ordinary characters before it
+ match 1 or more of the ordinary characters preceding it
() indicates that a character set is combined or used in an expression
| Represents "or", matching a set of optional characters
1. Symbols?
Example
Jo b Matching Job Joob
2. Symbol +
Example
S+eu Matching Sseu ssseu ...
3. Symbols () and symbols | Represents a set of optional characters
Example
Re (a|e|o) d matches read Reed Reod
4. Symbols |
Re1|re2|re3 ...
+++++++++++++++++++++++++++++++++++++++++++++++
Wildcard (Support bash shell)
Symbol * denotes any character of any bit
Symbol? Represents an arbitrary character
Symbol ^ indicates inverse
The symbol [] indicates that the character set fits
The symbol [^] denotes the inverse character set
The symbol {} represents the collection of a set of expressions
1. Symbols *
Example LS A * view all files starting with a
2. Symbols?
Example
LS a? View files with 2 characters beginning with a
3. Symbols []
Example
LS a[1-10] View a1.a2...a10
LS a[a-z]* view files with lowercase letters starting with a
4. Symbols [^]
Example
LS a[^1-2] View all files that do not contain A1,A2
5. Symbol {}
Example
LS a{[^1-2],a?,b*} View all files that do not contain A1,A2
or view files A and AA, or view all files that begin with B
This article is from the "Endmoon" blog, make sure to keep this source http://endmoon.blog.51cto.com/10533729/1682038
The regular expression of the shell script learning note