正则表达式中的 grep程序支持的meta字符plus和POSIX

grep程序支持的meta字符plus

字符

                                            模式含义

\<

瞄定单词的开始,如:’\<grep’匹配包含以grep开头的文件

\>

瞄定单词的结束,如:’\grep>’匹配包含以grep结尾的文件

\w

匹配文字和字符,也就是[A-Za_z1-9],如’G\w*p’匹配以G后跟零个或多个文字或字符

\W

\w的反置形式,匹配一个或多个非单词字符,如点号,句号等

\b

单词锁定符,如:’\bguo\b’只能匹配guo

举例:

[guo@guo~]$ cat test

goodecho

gooooood

luck

luckdfddf

good

goood

g,,,....d

1[guo@guo~]$ cat test

goodecho

gooooood

luck

luckdfddf

good

goood

2[guo@guo~]$ cat test |grep '\<good'

goodecho

good

3[guo@guo~]$ cat test |grep 'ood\>'

goodecho

gooooood

good

goood

[4guo@guo~]$ cat test |grep 'g\w*d'

goodecho

gooooood

good

goood

[guo@guo~]$ cat test |grep 'g\W*d'

g,,,....d

[guo@guo~]$ cat test |grep '\bgood\b'

goodecho

good

                                                     POSIX字符集

字符集

                              匹配字符

[:alnum:]

文字数字字符,等效于A-Za-z1-9

[:alpha:]

文字字符

[:black:]

空格(space)和定位(tab)字符

[:digit:]

数字字符

[:graph:]

非空字符(非空格、控制字符)

[:lower:]

小写字符

[:cntrl:]

控制字符

[:print:]

非空字符(包括空格)

[:punct:]

标点符号

[:space:]

所有空白字符(新行、空格、制表符)

[:upper:]

大写字符

[:xdigit:]

十六进制数



原文地址:https://www.cnblogs.com/linuxer/p/2272515.html