当前位置:网站首页>Introduction to regular expressions of shell, general matching, special characters: ^, $,., * Character range (brackets): [], special characters: \, matching mobile phone number
Introduction to regular expressions of shell, general matching, special characters: ^, $,., * Character range (brackets): [], special characters: \, matching mobile phone number
2022-07-27 04:29:00 【Redamancy06】
List of articles
1. Getting started with regular expressions
Regular expressions are described using a single string 、 Match a series of strings that conform to a certain syntax rule . In many text editors , Regular expressions are often used for retrieval 、 Replace the text that matches a pattern . stay Linux in ,grep,sed,awk And other text processing tools support pattern matching through regular expressions .
1.1 Regular match
A string of regular expressions without special characters matches itself , for example :
[[email protected] ~]# cat /etc/passwd | grep 00:
It will match all that contain 00: The line of .
1.2 Special characters are often used
1.2.1 Special characters :^
^ Match the beginning of a line , for example :
It will match all of them with a Beginning line
1.2.2 Special characters :$
$ Match the end of a line , for example 
It will match all of them with h The line at the end
- reflection :^$ Match what ?
Match blank line

daily_archive.sh File is in http://t.csdn.cn/0Wpml Written , If you want to see it, click here to see the contents
1.2.3 Special characters :.
Match an arbitrary character , for example 
1.2.4 Special characters :*
“*” Not used alone , He used it with the last character , Means to match the previous character 0 Times or times , for example
[[email protected] ~]# cat /etc/passwd | grep ro*t
Will match rt, rot, root, rooot, roooot Wait for all the lines
reflection :.* Match what ?
Match any character , You can talk to ^$ Continuous use , Put it among them , You can implement the following code , With a start ,login The line at the end 
[[email protected] ~]# cat /etc/passwd | grep ^a.*login$

[[email protected] ~]# cat /etc/passwd | grep ^a.*var.*login$
1.2.5 Character range ( brackets ):[ ]
[ ] Means to match a character in a range , for example
[6,8]------ matching 6 perhaps 8
[0-9]------ Match one 0-9 The number of
[0-9]------ Matches any length of numeric string
[a-z]------ Match one a-z Characters between
[a-z] ------ Matches an alphabetic string of any length
[a-c, e-f]- matching a-c perhaps e-f Any character between

[[email protected] ~]# cat /etc/passwd | grep r[a-z]*t
1.2.6 Special characters :\
\ To signify an escape , It will not be used alone . Because all special characters have their own matching patterns , When we want to match a particular character itself ( for example , I want to find out all the things that contain ‘$’ The line of ), There will be difficulties . At this point, we need to use escape characters with special characters , To represent the special character itself , for example

It will match all that contain $ The line of . Note that you need to use single quotes to cause the expression to .
1.2.7 Match cell phone number

[[email protected] scripts]# echo “13812345678” | grep ^1[34578][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$

[[email protected] scripts]# echo “13812345678” | grep -E ^1[34578][0-9]{9}$
Remember to capitalize -E, Because at present grep I won't support it {9} Extended regular , So we need to add -E, Express regular expressions that support extensions
边栏推荐
- Framework learning journey: init process startup process
- JMeter download and installation
- 对NIO的初步理解
- STM32基于HAL库的串口接受中断和空闲中断
- Database leader Wang Shan: strive for innovation and carefully Polish high-quality database products
- EVT interface definition file of spicy
- c# 获取uuid
- P1438 boring sequence line segment tree + difference
- 第二轮Okaleido Tiger即将登录Binance NFT,或持续创造销售神绩
- [leetcode] day104 no overlapping interval
猜你喜欢

Detailed explanation of TCP protocol knowledge

shel自动设置目录权限

The project parameters are made into configurable items, and the @configurationproperties annotation is used

e. The difference between target and e.currenttarget

Nacos startup and login

项目参数做成可配置项,@ConfigurationProperties注解的使用

Using webmvcconfigurer to intercept interface requests is being enhanced (with source code)

Echart柱状图中数据显示在图上方

Do you know about wechat merchant billing?

JMeter download and installation
随机推荐
EVT interface definition file of spicy
Head detached from origin/... Causes push failure
哈希表刷题(下)
webpack打包vue项目添加混淆方式,解决缓存问题
PX4模块设计之十二:High Resolution Timer设计
BigDecimal pit summary & Best Practices
通信协议综述
ISG index shows that the it and business service market in the Asia Pacific region fell sharply in the second quarter
[Code] sword finger offer 04 search in two-dimensional array
Eureka-服务注册中心
php+swoole
C get UUID
Word/excel has a fixed table size. When filling in the content, the table does not change with the cell content
Px4 module design 12: high resolution timer design
e.target与e.currentTarget的区别
Shell中的文本处理工具、cut [选项参数] filename 说明:默认分隔符是制表符、awk [选项参数] ‘/pattern1/{action1}filename 、awk 的内置变量
Playwright web crawler actual battle case sharing
Using webmvcconfigurer to intercept interface requests is being enhanced (with source code)
【机器学习网络】BP神经网络与深度学习-6 深度神经网络(deep neural Networks DNN)
Learning route from junior programmer to architect + complete version of supporting learning resources