当前位置:网站首页>Shell programming regular expressions and metacharacters
Shell programming regular expressions and metacharacters
2022-06-12 19:14:00 【benziwu】
Catalog
. : Match any single character
* : Match leader 0 To many times ; Can only be used later
[ ] : Match characters in the specified range
[^] Matches characters that are not in the specified group
\ : Used to escape metacharacters ('' "" \), Disjunctive sign
() A label that matches the characters used later
x\{m\} character x Recurring m Time
x\{m,n\} character x Recurring m To n Time
Extended regular expression metacharacter
+ matching 1~n Leading characters
? matching 0~1 Leading characters
Regular expressions
Metacharacters
Definition : Metacharacters are such characters , They express different literal meanings
^ : First locator
[[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
$ : End of line locator
. : Match any single character
[[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]ost ~]# grep .bc 1.txt
abc
[[email protected] ~]# grep ab. 1.txt
abc
* : Match leader 0 To many times ; Can only be used later
[[email protected] ~]# grep "abc*" 1.txt
abc
abcdffe
abcddfgh.* : Any number of characters
[[email protected] ~]# grep "ab.*" 1.txt
abc
abcdffe
abcddfgh
You are in /var/spool/mail/root New message in
[[email protected] ~]# grep "ab.*h" 1.txt
abcddfgh
[[email protected] ~]# grep "ab.*g" 1.txt
abcddfgh
[ ] : Match characters in the specified range
[[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
[^] Matches characters that are not in the specified group
similar ! stay “[]” ^ Mismatch

\ : Used to escape metacharacters ('' "" \), Disjunctive sign
[[email protected] ~]# grep "l." 1.txt
love
i love
i love you
l.ve
[[email protected] ~]# grep "l\." 1.txt
l.ve
\< Initial locators

\> Suffix locators
() A label that matches the characters used later


x\{m\} character x Recurring m Time
[[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\} character x Recurring m To n Time
[[email protected] ~]# grep "h\{3,5\}" 1.txt
hhhh
abcdefhhhgggff
Extended regular expression metacharacter
+ matching 1~n Leading characters
[[email protected] ~]# egrep lo+ve 1.txt
#love
i love
i love you
? matching 0~1 Leading characters
lo?ve:? Ahead o Yes or no , Will do !
[[email protected] ~]# egrep lo?ve 1.txt
#love
i love
i love you
lve
love
a|b matching a perhaps b

() Group character



边栏推荐
- Php+flash large file breakpoint continuation function sharing
- no available service ‘null‘ found, please make sure registry config correct
- Jenkins中pipeline对接CMDB接口获取主机列表的发布实践原创
- 【图像去噪】基于正则化实现图像去噪附matlab代码
- leetcode:98. Count the number of subarrays whose score is less than k [double pointers + number of calculated subsets + de duplication]
- 【0008】无序列表
- The 14th five year development plan and investment prospect analysis report of China's oil and gas pipeline engineering construction 2022-2027
- Chrome browser solves cross domain problems
- RT thread simulator builds lvgl development and debugging environment
- Super heavy! Apache Hudi multimode index optimizes queries up to 30 times
猜你喜欢

5G R17标准冻结,主要讲了些啥?

In 2021, the global revenue of electro-optical modulator (EOM) is about USD 360.3 million, and it is expected to reach USD 704.4 million in 2028

RT thread simulator builds lvgl development and debugging environment

一种灵活注入 Istio Sidecar 的方案探索

How do I create my own appender in log4j- How to create my own Appender in log4j?

ISCC2022

Chrome browser solves cross domain problems

liunx部署Seata(Nacos版)

I was badly hurt by the eight part essay...

论大型政策性银行贷后,如何数字化转型 ?-亿信华辰
随机推荐
Hugo blog building tutorial
Kali implements port forwarding through iptables
Detailed explanation of yolox network structure
Chrome browser solves cross domain problems
leetcode:5270. 网格中的最小路径代价【简单层次dp】
How do I create my own appender in log4j- How to create my own Appender in log4j?
什么是网络代理
Lua record
【数字IC/FPGA】数据累加输出
leetcode:6095. Strong password verifier II [simple simulation + direct false]
no available service ‘null‘ found, please make sure registry config correct
Meituan won the first place in fewclue in the small sample learning list! Prompt learning+ self training practice
leetcode:98. 统计得分小于 K 的子数组数目【双指针 + 计算子集个数 + 去重】
Attack and defense world (WEB) -- supersqli
【图像去噪】基于正则化实现图像去噪附matlab代码
chrome浏览器解决跨域问题
ISCC2022
Have a meal, dry pot, fat intestines + palm treasure!
leetcode:6094. 公司命名【分组枚举 + 不能重复用set交集 + product笛卡儿积(repeat表示长度)】
kali2022如何安装w3af