当前位置:网站首页>Regular expression
Regular expression
2022-07-01 18:40:00 【Hadron's blog】
One , What is regular expression
Regular expressions , Also known as regular expression . In code it is often abbreviated as regex、regexp or RE), A concept of computer science . Regular expressions are often used for retrieval 、 Replace those that match a pattern ( The rules ) The text of . There is more than one regular expression , and LINUX Different programs in may use different regular expressions , Tools :grep sed awk egrep
Regular expressions --- It is usually used to judge , Used to check whether a string satisfies a certain format ;
Regular expressions are composed of ordinary characters and metacharacters. Ordinary characters include upper and lower case letters 、 Numbers 、 Punctuation and some other symbolic metacharacters refer to special characters with special significance in regular expressions , It can be used to specify its leading characters ( The character before the metacharacter ) The occurrence pattern in the target object
Two , Basic regular expressions
Common metacharacters in basic regular expressions :( Supported tools :grep、egrep、sed、awk)
Special characters
\: Escape character , Escape special characters , Ignore its special significance a\.b matching a.b, But can't match ajb,. Be escaped as a special meaning
^: Match the beginning of the line ,^ Is the beginning of the matching string ^tux Match with tux Beginning line ^^^^
$: Match the end of the line ,$ Is the end of the matching string tux$ Match with tux The line at the end $$$$
.: Match break \r\n Any single character other than
[list]: matching list A character in the list example : go[ola]d,[abc]、[a-z]、[a-z0-9]
[^list]: Any match is not in list A character in the list example : [^a-z]、[^0-9]、[^A-Z0-9]
*: Match the front face expression 0 Times or more example :goo*d、go.*d
\{n\} : Match the previous subexpression n Time , example :go\{2\}d、'[O-9]\{2\}' Match two numbers
\{n,\}: Match the preceding subexpression no less than n Time , example : go\{2,\}d、' [0-9]\{2,\}' Match two or more digits
\{n,m\}﹔ Match the previous subexpression n To m Time , example : go\{2,3\)d、'[0-9]\{2,3\}' Match two to three digits
notes : egrep、awk Use {n}、{n, }、{n, m} When the match “{}" There is no need to add "\”
egrep -E -n 'wo{2}d' test.txt //-E Used to display the qualified characters in the file
egrep -E -n 'wo{2,3}d' test.txt
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
Locator
^ Matches where the input string starts
$ Matches the position of the end of the input string
Nonprinting characters
\n Match a line break
\r Match a carriage return
\t Match a tab
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
3、 ... and , Extended regular expression
( Supported tools : egrep、 awk)
+ : Match the front face expression 1 More than once , example : go+d, Will match at least one o, Such as god、 good、 goood etc.
? : Match the front face expression 0 Time or 1 Time , example : go?d, Will match gd or god
() : Use the string in parentheses as h all in one , example 1: g(oo)+d," Will match oo whole 1 More than once , Such as good、gooood etc.
| : Match a string of words by or , example : g (oo|la)d," Will match good perhaps glad
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
边栏推荐
- Lumiprobe 双功能交联剂丨Sulfo-Cyanine5 双-NHS 酯
- Mysql database of easyclick
- Xia CaoJun ffmpeg 4.3 audio and video foundation to engineering application
- This is the latest opportunity of the London bank trend
- Computer network interview assault
- [image denoising] matlab code for removing salt and pepper noise based on fast and effective multistage selective convolution filter
- Mujoco's biped robot Darwin model
- Data query language (DQL)
- Session layer of csframework, server and client (1)
- 2、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》启动并运行您的本地环境
猜你喜欢

Force buckle day33

Find all missing numbers in the array

6款红黄黑榜摄像头评测:谁最安全?谁画质好?从此让你不再踩雷

Extract the compressed package file and retrieve the password

Yolov5 practice: teach object detection by hand

What if the reliability coefficient is low? How to calculate the reliability coefficient?

Set the style of QT property sheet control

Lumiprobe 生物分子定量丨QuDye 蛋白定量试剂盒

How does factor analysis calculate weights?

Mujoco XML modeling
随机推荐
研究了11种实时聊天软件,我发现都具备这些功能…
LiveData postValue会“丢”数据
Mysql database of easyclick
[Chongqing Guangdong education] basic psychology reference materials of Tianjin Normal University
R语言ggplot2可视化:gganimate创建动态柱状图动画(gif)、在动画中沿给定维度逐步显示柱状图、enter_grow函数和enter_fade函数控制运动内插退出(渐变tweening)
Slider verification code identification gadget display
Session layer of csframework, server and client (1)
3、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》在本地铸造 NFT
Must see, time series analysis
Depth first search - DFS (burst search)
必看,时间序列分析
Financial judgment questions
力扣每日一题-第32天-1232. 缀点成线
Samba basic usage
Is the fund of futures account safe? How to open an account?
Rust language - cargo, crates io
因子分析怎么计算权重?
Database - MySQL advanced SQL statement (I)
Lumiprobe非荧光炔烃丨EU(5-乙炔基尿苷)
R语言使用dplyr包的transmute函数计算dataframe数据中的指定数据列的移动窗口均值、使用ggplot2包可视化移动均值与原始数据的折线图