A
detailed description of the regular expression
Ordinary characters: just literal meaning
Metacharacters: Meaning beyond the literal meaning
Basic regular expression meta-characters and their meanings
* The ordinary character before the #0个或多个在 * character
. #匹配任意字符
^ #匹配行首
$ #匹配行尾
$$ #执行上一条命令
!$ #上一条命令的最后一个参数, for example,/ETC/PASSWD, continues to operate on this parameter, which can be a cat!$
[] #匹配字符集合
\ #转义符
\{n\} #匹配前面字符出现n次
\{n,\} #匹配前面字符至少出现n次
\{n,m\} #匹配前面字符出现n-M times
Example
* Hel*o#可以匹配helll8o, Hello, Hellllo
. ... 73. #可以匹配abc73., [email protected] #73?, 12373c
^ ^... x86* #可以匹配以abcX86fang开头的字符
$ make$ #表示以make结尾
^$#表示空行
^.$ #表示某行只有一个字符
[A-z] #表示a-Z All lowercase letters
[0-9] #表示0-9 All numbers
[B-q] #表示b-Q Letters
[^b-q] #取反, except for all characters of b-q
[A-za-z] [a-za-z]* #能匹配任何一个英文单词
\*#将 \ The following meta-characters are converted to literal meanings
\<the\>#精确匹配, match only the word of the character, use \ Symbol mask <> sign grep ' \<the\> '
\{n\}#JO \{3\}b Match value is Jooob
\{n,\} #JO \{3,\}b Match value is Jooob Joooob Jooooooob
\{n,m\} #JO \{3,6\}b Match value is Jooob Jooooob Joooooob
[A-z] \{5\}#hello House whowh exactly match 5 lowercase letters
echo [abc]*Any multi-character file that is #开头为a/b/c
echo [^abc]*Any multi-character file that is #开头不是a/b/c
Touch {a,b,c}-{1,2,3} #通过穷举来创建文件, each file match to create a total of 9 files
!$ #上一条命令中的最后一个参数
; #表示命令结束
===========================================================================
extended Regular expression meta-characters and their meanings
? #匹配0个或1个在其之前的那个普通字符
+ #匹配1个或多个在其之前的那个普通字符
() #表示一个字符集合或用在expr中
| #表示或, match an optional set of characters
? JO? B #匹配JO1B [email protected] jo! B, match only one character. If it's job or jooob, it doesn't match.
+ S+eu #至少匹配前面的字符1次, you can match multiple
* S*u #可匹配S123U Ssuu [email protected] #U SU
() symbol and | symbol RE (a|e|o) d #匹配read Reed Reod
Example
1. List all files ending with. awk
ll *.awk
2. List the files starting with 0, followed by a word upper. Pem suffix
ll 0?. Pem
3. list files that begin with a letter in the A-h range and end with. awk
ll [A-h]*.awk
4. list files that begin with a letter in the A-h range and do not end with. awk after a period
ll [a-h]*. [^awk]*
5. list files that meet the letters beginning with the letter in the A-h range and end with. awk, or list files starting with 0 followed by a word upper with a. PEM suffix
ll {[a-h]*.awk,0?. Pem
---Regular expression of shell programming