基礎(chǔ)正則表達(dá)式

1.點(diǎn)符號(hào).(匹配任意一個(gè)字符,且只有一個(gè)字符 )

測試環(huán)境:

I am oldboy teacher!

I teach linux.

I like badminton ball ,billiard ball and chinese chess!

my blog is http://oldboy.blog.51cto.com

our site is http://www.etiantian.org

my qq num is 49000448.

not 4900000448.

my god ,i am not oldbey,but OLDBOY!

grep "." ~/oldboy_test.txt

I am oldboy teacher!

? ? ? I teach linux.

? ? ? I like badminton ball ,billiard ball and chinese chess!

? ? ? my blog is http://oldboy.blog.51cto.com

? ? ? our site is http://www.etiantian.org

? ? ? my qq num is 49000448.

? ? ? not 4900000448.

? ? ? my god ,i am not oldbey,but OLDBOY!

顯示匹配過程:

? ? ? [root@oldboyedu ~]# grep "." ~/oldboy_test.txt? -o

? ? ? I


? ? ? a

? ? ? m


? ? ? o

? ? ? l

? ? ? d

2.星符號(hào)*

匹配前一個(gè)字符連續(xù)出現(xiàn)了0次或者多次

[root@oldboyedu ~]# grep "0*" ~/oldboy_test.txt

? ? ? I am oldboy teacher!

? ? ? I teach linux.

? ? ? I like badminton ball ,billiard ball and chinese chess!

? ? ? my blog is http://oldboy.blog.51cto.com

? ? ? our site is http://www.etiantian.org

? ? ? my qq num is 49000448.


? ? ? not 4900000448.

? ? ? my god ,i am not oldbey,but OLDBOY!

3.點(diǎn)和星結(jié)合(匹配任意所有信息 類似于通配符*)

[root@oldboyedu ~]# grep "^m.*m$" ~/oldboy_test.txt 以m開頭 m結(jié)尾 中間內(nèi)容不管的所有匹配

指定具體信息阻止貪婪匹配

? ? ? [root@oldboyedu ~]# grep "^m.*to" ~/oldboy_test.txt

4.轉(zhuǎn)義字符

echo -e "oldboy01\noldboy02\noldboy03" // -e 拓展識(shí)別 不加識(shí)別不了\n

5.中括號(hào)[]

匹配多個(gè)字符信息

grep "oldb[oe]y" oldboy_test.txt??

將以I開頭和m開頭的行都找出來

grep "^[lm]" oldboy_test.txt

6. 括號(hào)和尖號(hào)組合 [^]

排除符號(hào)

grep "^[^abc]" oldboy_test.txt //找出不是a b c 開頭的


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容