当前位置:网站首页>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.
边栏推荐
- Sum of three numbers
- How to find customers for investment attraction in industrial parks
- Data query language (DQL)
- When the fixed frequency artifact falls in love with multithreading | ros2 fixed frequency topic release demo
- R语言ggplot2可视化:gganimate创建动态柱状图动画(gif)、在动画中沿给定维度逐步显示柱状图、enter_grow函数和enter_fade函数控制运动内插退出(渐变tweening)
- Yuancosmos game farmersworld farmers world - core content of the second conference in China!
- 主成分计算权重
- Flex layout
- Fix the black screen caused by iPhone system failure
- What impact will multinational encryption regulation bring to the market in 2022
猜你喜欢
Localization through custom services in the shuttle application
Static timing analysis (STA) in ic/fpga design
Samba basic usage
. Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
Bernoulli distribution (a discrete distribution)
Leetcode-128 最长连续序列
540. Single element in ordered array / 1684 Count the number of consistent strings
How to find the optimal learning rate
每周推荐短视频:警惕“现象”与“问题”相互混淆
LeetCode-21合并两个有序链表
随机推荐
R语言ggplot2可视化:gganimate包transition_time函数创建动态散点图动画(gif)、shadow_wake函数配置动画的渐变效果(gradual falloff)拖尾效应
Calculation of intersection of two line segments
SCP -i private key usage
Set the style of QT property sheet control
Five degrees easy chain enterprise app is newly upgraded
Find all missing numbers in the array
Samba basic usage
Principal component calculation weight
[image denoising] matlab code for removing salt and pepper noise based on fast and effective multistage selective convolution filter
PMP daily three questions (February 15, 2022)
540. Single element in ordered array
Facebook聊单,SaleSmartly有妙招!
Pytorch crossentropyloss learning
Domestic spot silver should be understood
Definition of rotation axis in mujoco
Leetcode203 移除链表元素
[noip2015] jumping stone
Yuancosmos game farmersworld farmers world - core content of the second conference in China!
C# SelfHost WebAPI (2)
Small exercise -- subnet division and summary