当前位置:网站首页>Shell 编程正则表达式及元字符
Shell 编程正则表达式及元字符
2022-06-12 19:03:00 【benziwu】
目录
正则表达式
元字符
定义:元字符是这样一类字符,他们表达的是不同字面本身的含义
^ :首位定位符
[[email protected] ~]# grep "root" /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[[email protected] ~]# grep "^root" /etc/passwd
root:x:0:0:root:/root:/bin/bash
$ :行尾定位符
. :匹配任意单个字符
[[email protected] ~]# cat 1.txt
abc
adc
bac
[[email protected] ~]# grep abc 1.txt
abc
[[email protected] ~]# grep a.c 1.txt
abc
adc
[[email protected] ~]# grep ..c 1.txt
abc
adc
bac
[[email protected] ~]# grep .bc 1.txt
abc
[[email protected] ~]# grep ab. 1.txt
abc
* :匹配前导符0到多次;只能在后面使用
[[email protected] ~]# grep "abc*" 1.txt
abc
abcdffe
abcddfgh.* :任意多个字符
[[email protected] ~]# grep "ab.*" 1.txt
abc
abcdffe
abcddfgh
您在 /var/spool/mail/root 中有新邮件
[[email protected] ~]# grep "ab.*h" 1.txt
abcddfgh
[[email protected] ~]# grep "ab.*g" 1.txt
abcddfgh
[ ] : 匹配指定范围内的字符
[[email protected] ~]# grep [iL]ove 1.txt
Love
[[email protected] ~]# cat 1.txt
abc
adc
bac
abcdffe
abcddfgh
ggg
love
LOve
Love
i love
i love you
hhhh
[[email protected] ~]# grep [lL]ove 1.txt
love
Love
i love
i love you
[^] 匹配不在指定组内的字符
类似!在“[]” ^ 不匹配

\ :用来转义元字符('' "" \),脱意符
[[email protected] ~]# grep "l." 1.txt
love
i love
i love you
l.ve
[[email protected] ~]# grep "l\." 1.txt
l.ve
\< 词首定位符

\> 词尾定位符
() 匹配稍后使用的字符的标签


x\{m\} 字符x重复出现m次
[[email protected] ~]# grep o 1.txt
#love
Love
i love
i love you
[[email protected] ~]# grep "h\{3\}" 1.txt
hhhh
abcdefhhhgggff
![]()
x\{m,n\} 字符x重复出现m到n次
[[email protected] ~]# grep "h\{3,5\}" 1.txt
hhhh
abcdefhhhgggff
扩展正则表达式元字符
+ 匹配1~n个前导字符
[[email protected] ~]# egrep lo+ve 1.txt
#love
i love
i love you
? 匹配0~1个前导字符
lo?ve:? 前面的o有还是没有,都行!
[[email protected] ~]# egrep lo?ve 1.txt
#love
i love
i love you
lve
love
a|b 匹配a或者b

() 组字符



边栏推荐
- io.seata.common.exception.FrameworkException: can not connect to services-server.
- liunx部署Seata(Nacos版)
- Common troubleshooting tools and analysis artifacts are worth collecting
- Experiment 10 Bezier curve generation - experiment improvement - control point generation of B-spline curve
- Lua record
- Uniapp uses the Ali Icon
- 觀察網站的頁面
- Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of swimming fins in the global market in 2022
- Go package import mode member visibility
- Leetcode 474. One and zero
猜你喜欢

嵌入式开发:固件工程师的6项必备技能

The Bean Validation API is on the classpath but no implementation could be found

攻防世界(web篇)---supersqli

数据库全量SQL分析与审计系统性能优化之旅

leetcode:6096. 咒语和药水的成功对数【排序 + 二分】
![leetcode:6096. Success logarithm of spells and potions [sort + dichotomy]](/img/af/0d6ea1a25e65962616b2b049711510.png)
leetcode:6096. Success logarithm of spells and potions [sort + dichotomy]

【0008】无序列表

leetcode:5259. 计算应缴税款总额【简单模拟 + 看看在哪个区间】

【图像去噪】基于各向异性滤波实现图像去噪附matlab代码

一种灵活注入 Istio Sidecar 的方案探索
随机推荐
国内如何下载Vega
Experiment 10 Bezier curve generation - experiment improvement - interactive generation of B-spline curve
Meituan won the first place in fewclue in the small sample learning list! Prompt learning+ self training practice
【矩阵论 & 图论】期末考试复习思维导图
kali2022如何安装w3af
leetcode:6096. Success logarithm of spells and potions [sort + dichotomy]
Redis(三十二)-用Redis做分布式锁
How to break the black screen after cleaning the dust and applying silicone grease on the laptop?
tarfile解压嵌套tar
软件确认测试知识分享,上海第三方软件测试机构有哪些?
Liunx deploy Seata (Nacos version)
Leetcode 416. Split equal sum subset
leetcode:6094. Company name [group enumeration + cannot repeat set intersection + product Cartesian product (repeat indicates length)]
OpenGL shadow implementation (soft shadow)
Observe the page of the website
CVPR 2022 Oral 大连理工提出SCI:快速、超强的低光照图像增强方法
Leetcode topic [string] - Sword pointing offer 05- replace spaces
Delivery lead time lightweight estimation practice - Notes
The Bean Validation API is on the classpath but no implementation could be found
232-CH579M学习开发-以太网例程-TCP服务器(项目应用封装,局域网或广域网测试)