当前位置:网站首页>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.
边栏推荐
- LeetCode 148. Sort linked list
- 每周推荐短视频:警惕“现象”与“问题”相互混淆
- The ultimate version of the 13th simulation of the single chip microcomputer provincial competition of the Blue Bridge Cup
- Basic concepts of binary tree
- Small exercise -- subnet division and summary
- What impact will multinational encryption regulation bring to the market in 2022
- Domestic spot silver should be understood
- Vue uses keep alive to cache page optimization projects
- Must see, time series analysis
- Cloud computing - make learning easier
猜你喜欢
How to find customers for investment attraction in industrial parks
Explain in detail the process of realizing Chinese text classification by CNN
研究了11种实时聊天软件,我发现都具备这些功能…
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
PCL learning materials
Leetcode-141环形链表
Android development interview was badly hit in 3 years, and now the recruitment technical requirements are so high?
How does factor analysis calculate weights?
12. Design of power divider for ads usage record
2、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》启动并运行您的本地环境
随机推荐
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
How does factor analysis calculate weights?
PTA year of birth
Yolov5 practice: teach object detection by hand
Five degrees easy chain enterprise app is newly upgraded
The ultimate version of the 13th simulation of the single chip microcomputer provincial competition of the Blue Bridge Cup
R语言使用dplyr包的transmute函数计算dataframe数据中的指定数据列的移动窗口均值、使用ggplot2包可视化移动均值与原始数据的折线图
因子分析怎么计算权重?
Force buckle day33
Lumiprobe Lumizol RNA 提取试剂解决方案
Record 3 - the state machine realizes key control and measures the number of external pulses
LeetCode-21合并两个有序链表
Is the fund of futures account safe? How to open an account?
力扣每日一题-第32天-1232. 缀点成线
关于企业中台规划和 IT 架构微服务转型
Is Alipay wallet convenient to use?
C operator overloads the query table
What if the reliability coefficient is low? How to calculate the reliability coefficient?
Localization through custom services in the shuttle application
Mysql database design