当前位置:网站首页>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.
边栏推荐
- Definition of rotation axis in mujoco
- [Chongqing Guangdong education] basic psychology reference materials of Tianjin Normal University
- R语言epiDisplay包ordinal.or.display函数获取有序logistic回归模型的汇总统计信息(变量对应的优势比及其置信区间、以及假设检验的p值)、write.csv函数保存csv
- Mujoco model learning record
- Vue uses keep alive to cache page optimization projects
- [source code analysis] NVIDIA hugectr, GPU version parameter server - (1)
- Implementation of converting PCM file to WAV
- Happy new year | 202112 monthly summary
- Computer network interview assault
- NSI packaging script add file details
猜你喜欢
Depth first search - DFS (burst search)
Bug of QQ browser article comment: the commentator is wrong
Android development interview was badly hit in 3 years, and now the recruitment technical requirements are so high?
Mujoco XML modeling
Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"
Must see, time series analysis
Xia CaoJun ffmpeg 4.3 audio and video foundation to engineering application
Principal component calculation weight
Leetcode-83 删除排序链表中重复的元素
Sum of three numbers
随机推荐
信度系数低怎么办?信度系数具体怎么算?
Lumiprobe 双功能交联剂丨Sulfo-Cyanine5 双-NHS 酯
Facebook聊单,SaleSmartly有妙招!
Win10+vs2019 Community Edition compiling OpenSSL
Blue Bridge Cup real topic: the shortest circuit
This is the latest opportunity of the London bank trend
R语言ggplot2可视化:gganimate包transition_time函数创建动态散点图动画(gif)、shadow_wake函数配置动画的渐变效果(gradual falloff)拖尾效应
Convert the robot's URDF file to mujoco model
Principal component calculation weight
t10_ Adapting to Market Participantsand Conditions
Classpath classpath
PCL learning materials
Domestic spot silver should be understood
What impact will multinational encryption regulation bring to the market in 2022
Extract the compressed package file and retrieve the password
Bug of QQ browser article comment: the commentator is wrong
Android development interview was badly hit in 3 years, and now the recruitment technical requirements are so high?
Data query language (DQL)
How to find customers for investment attraction in industrial parks
Roll out! Enlightenment!