当前位置:网站首页>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 10:00: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
边栏推荐
- Write yourself a year-end summary. Happy New Year!
- What age are you still using date
- Brush the title "sword finger offer" day03
- Talk about 10 scenarios of index failure. It's too stupid
- QT learning (II) -- a brief introduction to QT Creator
- How to install cpolar intranet penetration on raspberry pie
- Snowflake vs. Databricks谁更胜一筹?2022年最新战报
- Understand chisel language. 22. Chisel sequential circuit (II) -- detailed explanation of chisel counter: counter, timer and pulse width modulation
- July training (day 14) - stack
- wordpress禁止指定用户名登录或注册插件【v1.0】
猜你喜欢

Sentinel ten thousand word tutorial | book delivery at the end of the text

Why do microservices have to have API gateways?

Qt 学习(二) —— Qt Creator简单介绍

深度剖析分库分表最强辅助Sharding Sphere
![Shell的正则表达式入门、常规匹配、特殊字符:^、$、.、*、字符区间(中括号):[ ]、特殊字符:\、匹配手机号](/img/31/ed0d8c1a5327059f2de7493bec1c6c.png)
Shell的正则表达式入门、常规匹配、特殊字符:^、$、.、*、字符区间(中括号):[ ]、特殊字符:\、匹配手机号

圆环工件毛刺(凸起)缺口(凹陷)检测案例

语音直播系统——开发推送通知需要遵守的原则

LeetCode.814. 二叉树剪枝____DFS

Provincial Emergency Management Department: Guangzhou can strive to promote the experience of emergency safety education for children

华为交换机双上行组网Smart-link配置指南
随机推荐
Brush the title "sword finger offer" day04
S交换机堆叠方案配置指南
Engineering survey simulation volume a
Explain knative cloud function framework in simple terms!
Understand chisel language. 26. Chisel advanced input signal processing (II) -- majority voter filtering, function abstraction and asynchronous reset
省应急管理厅:广州可争取推广幼儿应急安全宣教经验
并发之线程状态转换
Interview JD T5, was pressed on the ground friction, who knows what I experienced?
July training (day 07) - hash table
[cloud native] how can I compete with this database?
What age are you still using date
July training (day 11) - matrix
[scm] source code management - lock of perforce branch
GO基础知识—数组和切片
XML overview
好久不送书,浑身不舒服
Summary of engineering material knowledge points (full)
吃透Chisel语言.22.Chisel时序电路(二)——Chisel计数器(Counter)详解:计数器、定时器和脉宽调制
7/26 思维+dp+后缀数组的学习
[SCM]源码管理 - perforce 分支的锁定