系统正则符号

基础正则:basic regular exprssion =====BRE
扩展正则:extended regular exprssion===ERE

基础正则

^符号:以什么开头

例如:grep "^#" /etc/services

$符号:以什么结尾

例如:grep "d$" /etc/selinux/config

PS:^$表示空行

.点:匹配任意单个字符

例如:grep "^." /etc/selinux/config

*星号:匹配前一个字符连续出现0次或者多次

例如:grep "#*" /etc/selinux/config

PS:.*表示文件中整体信息

[]中括号:匹配中括号中任意一个字符

例如:grep "[a-z]" /etc/selinux/config

PS:[^]表示将指定的字符信息取反

扩展正则

+加号:匹配前一个字符连续出现1次或者多次

例如:
[root@oldboy0708 ~]# egrep "#+" /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
        # ksh workaround
# Path manipulation
# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file

|管道符号:匹配多个字符信息

例如:
[root@oldboy0708 ~]# egrep "DNS1|DNS2" /etc/sysconfig/network-scripts/ifcfg-eth0
DNS1=223.5.5.5
DNS2=223.6.6.6

()小括号:

1、将多个字符信息整合过滤
2、实现后项引用前项进行替换(常用)

例如:
[root@oldboy0708 ~]# echo "123456"|sed 's#[0-9]\+#<&>#g'
<123456>
\转义符号:(不属正则)

1、将有特殊意义的符号还原本身符号意义
2、将没有意义的符号变为有意义的
3、可将扩展正则符号转换为普通正则

你可能感兴趣的:(系统正则符号)