好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > 詳解Linux中正則表達式的應用

詳解Linux中正則表達式的應用

熱門標簽:外呼系統無呼出路由是什么原因 400電話辦理電話辦理 ai電話機器人搭建 貴港公司如何申請400電話 西藏智能外呼系統代理商 呼叫系統外呼只能兩次 梅縣地圖標注 地圖標注教學點 甘肅醫療外呼系統排名

1、組成

普通字符:普通字符串,沒有特殊含義
特殊字符:在正則表達式中具有特殊的含義
正則表達式中常見的meta字符【特殊字符】

2、POSIX BRE【基本】與ERE【擴展】中都有的meta字符

\ :通常用于打開或關閉后續字符的特殊含義,如(...)【\是轉義字符,去掉符號的特殊意義,()、{}等在shell中都有特殊的意義】
.和以及.的區別:

[root@localhost ~]# cat -n test.txt
     1  gd
     2  god
     3
     4  good
     5  goood
     6  goad
     7
     8  gboad

2.1、. :匹配任意單個字符(除null,即不能為空)

[root@localhost ~]# grep -n "." test.txt      
1:gd
2:god
4:good
5:goood
6:goad
8:gboad
[root@localhost ~]# grep -n "go.d" test.txt
4:good
6:goad

2.2、 :匹配其前字符任意次,如o,可以是沒有o或者一個o,也可以是多個o

[root@localhost ~]# grep -n "*" test.txt
[root@localhost ~]# grep -n "o*" test.txt
1:gd
2:god
3:
4:good
5:goood
6:goad
7:
8:gboad
[root@localhost ~]# echo "gbad" >>test.txt
[root@localhost ~]# echo "pbad" >>test.txt
[root@localhost ~]# echo "kgbad" >>test.txt
[root@localhost ~]# echo "poad" >>test.txt  
[root@localhost ~]# grep -n "go*" test.txt 【o可以沒有,o前面的g一定要匹配】
1:gd
2:god
4:good
5:goood
6:goad
8:gboad
9:gbad
11:kgbad

*2.3、. :匹配任意字符(匹配所有),可以為空**

[root@localhost ~]# grep -n ".*" test.txt
1:gd
2:god
3:
4:good
5:goood
6:goad
7:
8:gboad
9:gbad
10:pbad
11:kgbad
12:poad
[root@localhost ~]# grep -n "go.*" test.txt
2:god
4:good
5:goood
6:goad
[root@localhost ~]# grep -n "po.*" test.txt 
12:poad
[root@localhost ~]# echo "pgoad" >>test.txt   
[root@localhost ~]# grep -n "go.*" test.txt  【匹配go后存在任意字符,可為空】
2:god
4:good
5:goood
6:goad
13:pgoad
[root@localhost ~]#
[root@localhost ~]# grep -n "o.*" test.txt 
2:god
4:good
5:goood
6:goad
8:gboad
12:poad

2.4、^ :匹配緊接著后面的正則表達式,以...為開頭

[root@localhost tmp]# grep "^root" /etc/passwd
root:x:0:0:root:/root:/bin/bash
[root@localhost tmp]#

2.5、$ :匹配緊接著前面的正則表達式,以...結尾

[root@localhost tmp]# grep "bash$" /etc/passwd | head -1
root:x:0:0:root:/root:/bin/bash
[root@localhost tmp]#
^$:表示是空行的意思
“#|^$”:匹配以#號開頭的注釋行和空行

2.6、[] :匹配方括號里的任一字符

(如[sS],匹配s或匹配S),其中可用連字符(-)指定連字符的范圍(如[(0-9)],匹配0-9任一字符);[^0-9]如果^符號出現在方括號的第一個位置,則表示匹配不在列表中的任一字符。

[root@localhost tmp]# cat hosts
192.168.200.1
192.168.200.3
a.b.123.5
23.c.56.1
1456.1.2.4
12.4.5.6.8
[root@localhost tmp]# grep -E '([0-9]{1,3}\.){3}[0-9]{1,3}' hosts  
192.168.200.1
192.168.200.3
1456.1.2.4
12.4.5.6.8
[root@localhost tmp]# grep -E '^([0-9]{1,3}\.){3}[0-9]{1,3}$' hosts
192.168.200.1
192.168.200.3
[root@localhost tmp]#

2.7、? :匹配前面字符的零次或多次

[root@localhost ~]# grep -E "go?d" test.txt  
gd
god
[root@localhost ~]#
[root@localhost tmp]# cat test
do
does
doxy
[root@localhost tmp]# grep -E "do(es)?" test
do
does
doxy
[root@localhost tmp]#

3、POSIX BRE(基本正則)中才有的字符

{n,m} :區間表達式,匹配在它前面的單個字符重現【重復,緊接著的單個字符如https{0,1},即重復s 0-1次。{n}指匹配n次;{n,m}指匹配n至m次,{n,}指匹配至少n次,{,m}匹配至多m次。【\轉義字符】

4、POSIX ERE(擴展正則)中才有的字符

4.1、{n,m} :與BRE的{n,m}功能相同

[root@localhost tmp]# grep -E '^([0-9]{1,3}\.){3}[0-9]{1,3}$' hosts
192.168.200.1
192.168.200.3

4.2、+ :匹配前面正則表達式的一次或多次

[root@localhost ~]# egrep "go+d" test.txt
god
good
goood
[root@localhost ~]#

4.3、| :表示匹配多個字符串【或的關系】

[root@localhost ~]# grep -E "3306|1521" /etc/services
mysql           3306/tcp                        # MySQL
mysql           3306/udp                        # MySQL
ncube-lm        1521/tcp                # nCube License Manager
ncube-lm        1521/udp                # nCube License Manager
[root@localhost ~]#

4.4、( ) :分組過濾,后向引用

分組過濾   

[root@localhost ~]# echo "glad" >> test.txt
[root@localhost ~]# egrep "(la|oo)" test.txt
good
goood
glad

()后向引用;當前面匹配部分用小括號的時候,第一個括號的內容可以在后面部分用\1輸出;以此類推。

 [root@localhost tmp]# ifconfig |sed -rn 's#.*addr:(.*)(B.*)$#\1#gp'
192.168.4.27 

5、正則表達式的元字符

5.1、\b :匹配一個單詞邊界

[root@localhost tmp]# cat test       
do
does
doxy
agdoeg
[root@localhost tmp]# grep "do\b" test
do
[root@localhost tmp]# grep "\bdo" test       
do
does
doxy
[root@localhost tmp]# grep "\bdoes" test         
does
[root@localhost tmp]# grep "\bdo\b" test 
do
[root@localhost tmp]#

5.2、\B :匹配非單詞邊界,與\b相反

[root@localhost tmp]# grep "do\B" test   
does
doxy
agdoeg
[root@localhost tmp]# grep "do\b" test
do
[root@localhost tmp]#

5.3、\d :匹配一個數字字符,等價于[0-9]

5.4、\D :匹配一個非數字字符,等價于[^0-9]

5.5、\w :匹配字母、數字、下劃線,等價于[A-Za-z0-9_]

還有很多元字符,這里就不一一羅列出來

案例:開機精簡

[root@localhost ~]# chkconfig --list| egrep -v "crond|network|rsyslog|sshd|sysstat" | awk '{print "chkconfig",$1,"off"}'|bash

您可能感興趣的文章:
  • Linux 正則表達式詳解
  • linux grep正則表達式與grep用法詳解
  • linux 正則表達式深度解析
  • linux正則表達式awk詳解
  • 使用Linux正則表達式靈活搜索文件中的文本
  • linux下的通配符與正則表達式
  • linux shell 路徑截取正則表達式
  • 淺談Linux grep與正則表達式
  • linux shell 正則表達式(BREs,EREs,PREs)差異比較

標簽:常州 海口 泰安 本溪 涼山 哈密 大興安嶺 湖州

巨人網絡通訊聲明:本文標題《詳解Linux中正則表達式的應用》,本文關鍵詞  詳解,Linux,中,正則,表達式,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《詳解Linux中正則表達式的應用》相關的同類信息!
  • 本頁收集關于詳解Linux中正則表達式的應用的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 精品人妻无码一区二区三区淑枝| 成人羞羞漫画在免费线观看| 久久综合网久久综合| japaneseXXⅩHD麻豆| 91亚洲国产成人久久精品网址| 操美女的视频网站| 爱豆传媒在线电影播放| 色天使色偷偷色噜噜最新版本下载| 亚洲欧美圣爱天天综合| 国产秘?精品区二区三区日本| 亚洲精品乱码久久久久久9色| 日本视频一区二区免费播放| 大学生久久香蕉国产线看观看| 欧美 亚洲 武侠 另类 动漫| ysl蜜桃色7777| 国产伦精一品二品三品观看方法| 男女过程很爽的视频网站| 听书大全免费| 亚洲欧美日韩不卡一区二区三区 | 99国产精品农村一级毛片| JUY-974暴风雨和上司中出| 久久午夜夜伦鲁鲁片无码免费| 乳妾(宫廷H)| 欧美丰满熟妇XXXXX性PPx人交| 国产精品秘?久久入口| 在线二区| 汤芳人体《魅惑2》| www.qqq258.com| 91中文在线观看| 9420高清完整版视频在线观看中文| 美女跪下吃男人的J8视频| 国产一区二区三区电影在线观看| 97精品视频一区二区| XXXXXL19D18日本| 久久免费视频观看| 91丝袜??国产在线观看| 欧美粗又大gay69视频 | 精品国偷自产国产一区| 免费观**网站| 国产主播一区二区三区| 黄金大劫案|