当前位置:网站首页>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.
边栏推荐
- What impact will multinational encryption regulation bring to the market in 2022
- Search 2D matrix 2
- C# SelfHost WebAPI (2)
- Xia CaoJun ffmpeg 4.3 audio and video foundation to engineering application
- Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
- 主成分计算权重
- [source code analysis] NVIDIA hugectr, GPU version parameter server - (1)
- R语言使用epiDisplay包的dotplot函数通过点图的形式可视化不同区间数据点的频率、使用pch参数自定义指定点图数据点的形状
- PTA year of birth
- [Chongqing Guangdong education] basic psychology reference materials of Tianjin Normal University
猜你喜欢

This is the latest opportunity of the London bank trend

Blue Bridge Cup real topic: the shortest circuit

Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash

Fix the black screen caused by iPhone system failure

Computer network interview assault

Domestic spot silver should be understood

Mysql database of easyclick

Find all missing numbers in the array

Mujoco XML modeling

Data query language (DQL)
随机推荐
Single element of an ordered array
12种数据量纲化处理方式
Rust language - cargo, crates io
Lumiprobe 双功能交联剂丨Sulfo-Cyanine5 双-NHS 酯
力扣每日一题-第32天-1232. 缀点成线
Implementation of converting PCM file to WAV
(6) VIM editor MV cat redirection standard input and output more pipe symbols head tail
Review Net 20th anniversary development and 51aspx growth
The method of real-time tracking the current price of London Silver
Three.js学习-相机Camera的基本操作(了解向)
信度系数低怎么办?信度系数具体怎么算?
Introduction to easyclick database
Extract the compressed package file and retrieve the password
Definition of rotation axis in mujoco
MySQL connection tools
Classpath classpath
The 13th simulation problem of the single chip microcomputer provincial competition of the Blue Bridge Cup
[noip2015] jumping stone
每周推荐短视频:警惕“现象”与“问题”相互混淆
PTA year of birth