17个案例带你3分钟搞定Linux正则表达式

正则表达式是一种字符模式,用于在查找过程当中匹配制定的字符。linux

元字符一般在Linux中分为两类:正则表达式

Shell元字符,由Linux Shell进行解析;spring

正则表达式元字符,由vi/grep/sed/awk等文本处理工具进行解析;工具

正则表达式通常以文本行进行处理,在进行下面实例以前,先为grep命令设置--color参数:测试

 

$ alias grep='grep --color=auto'

这样每次过滤出来的字符串都会带色彩了。code

在开始以前还须要作一件事情,就是建立一个测试用的re-file文件,内容以下:blog

 

$ cat re-file
I had a lovely time on our little picnic.
Lovers were all around us. It is springtime. Oh
love, how much I adore you. Do you know
the extent of my love? Oh, by the way, I think
I lost my gloves somewhere out in that field of
clover. Did you see them?  I can only hope love.
is forever. I live for you. It's hard to get back in the
groove.

文件内容摘录自<<UNIX/SHELL范例精解第四版>>字符串

 

$ cat linux.txt
Linux is a good 
god assdxw bcvnbvbjk
greatttttt  wexcvxc
operaaaating  dhfghfvx
gooodfs awrerdxxhkl
gdsystem awxxxx
glad
good

正则表达式元字符get

5ca94856bce6225907e84d25fb88930268647345

特殊的元字符it

相关文章
相关标签/搜索