一 基础正则表达式
?和()是扩展正则。
二 “*”前一个字符匹配0次,或任意多次
三 “.”匹配除了换行符外任意一个字符
四 “^”匹配行首,“$”匹配行尾
五 “[]”匹配中括号中指定的任意一个字符,只匹配一个字符
六 “[^]”匹配除中括号的字符以外的任意一个字符
七 “”转义符
“.$”
匹配使用“.”结尾的行
八 “{n}”表示其前面的字符恰好出现n次
九 “{n,}”表示其前面的字符出现不小于n次
十 “{n,m}”表示其前面的字符至少出现n次,最多出现m次
十一 范例文档
a
aa
aaa
aaaa
aaaaa
c
cc
xcccu
xccccu
xcccccu
said
soid.
suud
soooooooooood.
12345
5678
7832
bbbbbb45bbbb
6aaaaaaaaaaaa
ab
aabb
十二 匹配日期和IP
[root@localhost ~]# grep "[0-9]{4}-[0-9]{2}-[0-9]{2}" test.txt
2016-02-14
[root@localhost ~]# vim test.txt
[root@localhost ~]# grep "[0-9]{1,3}.[0-9]{1,3}" test.txt
192.108.4.2
194.6.3.98