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

相關文章
相關標籤/搜索