当前位置:网站首页>regular expression
regular expression
2022-07-07 12:57:00 【LC181119】
1. Basic regular expression metacharacters
1.1 Character matching
- . Match any single character , It can be a Chinese character
- [] Match any single character in the specified range
- [^] Matches any single character outside the specified range
- [:alnum:] Represents any upper and lower case letters in English
- [:lower:] Lowercase letters
- [:upper:] Capital
- [:blank:] Blank character ( Spaces and tabs )
- [:space:] Including Spaces 、 tabs ( Horizontal or vertical )、 A newline 、 Various types of whitespace such as carriage return
- [:cntrl:] Non printable control characters ( Backspace 、 Delete 、 Alarm bell ...)
- [:digit:] Decimal number
- [:xdigit:] Hexadecimal number
- [:graph:] Printable non blank characters
- [:print:] Printable characters
- [:punct:] Punctuation
- \w Components of matching words , Equivalent to [_[:alnum:]]
- \W Match non word components , Equivalent to [^_[:alnum:]]
- \S Matches any non-whitespace characters , Equivalent to [^ \f\n\r\t\v]
- \s Matches any whitespace characters , Including Spaces 、 tabs 、 Page breaks and so on , amount to [ \f\n\r\t\v].
Be careful :unicode Regular expressions match full space characters .
1.2 Number of matches
Used after the character to specify the number of times , Used to specify the number of times the preceding characters will appear
- * Match preceding characters any number of times , Include 0 Time , Greedy mode , Match as long as possible
- .* Any character of any length
- \? Match the character before it to appear 0 Time or 1 Time , namely : not essential
- \+ Matches the least characters that precede it 1 Time , namely : There must be and >=1 Time
- \{n\} Match preceding characters n Time
- \{m,n\} Match preceding characters at least m Time , at most n Time
- \{,n\} Match preceding characters up to n Time ,<=n
- \{n,\} Match preceding characters at least n Time
1.3 Position anchoring
- ^ Anchor anchoring , Leftmost rule for mode
- $ Tail anchoring , For the far right side of the pattern
- ^PATTERN$ For pattern matching entire line
- ^$ Blank line
- ^[[:space:]]*$ Blank line
- \< or \b Initial anchoring , For the left side of the word pattern
- \> or \b Suffix anchor , For the right side of the word pattern
- \<PATTERN> Match the whole word
1.4 grouping
1.5 perhaps
perhaps :\|
2. Extended regular expression metacharacter
2.1 Character matching
- . Match any single character , It can be a Chinese character
- [] Match any single character in the specified range
- [^] Matches any single character outside the specified range
- [:alnum:] Represents any upper and lower case letters in English
- [:lower:] Lowercase letters
- [:upper:] Capital
- [:blank:] Blank character ( Spaces and tabs )
- [:space:] Including Spaces 、 tabs ( Horizontal or vertical )、 A newline 、 Various types of whitespace such as carriage return
- [:cntrl:] Non printable control characters ( Backspace 、 Delete 、 Alarm bell ...)
- [:digit:] Decimal number
- [:xdigit:] Hexadecimal number
- [:graph:] Printable non blank characters
- [:print:] Printable characters
- [:punct:] Punctuation
2.2 Number matching
- * Match preceding characters any number of times
- ? 0 or 1 Time
- + 1 Times or times
- {n} matching n Time
- {m,n} At least m, at most n Time
2.3 Position anchoring
- ^ Head of line
- $ At the end of the line
- \<, \b Initials
- \>, \b At the end of the sentence
2.4 Group other
- () grouping
- Backward reference :\1, \2, ...
- | perhaps
- a|b #a or b
- C|cat #C or cat
- (C|c)at #Cat or cat
边栏推荐
- [statistical learning methods] learning notes - Chapter 4: naive Bayesian method
- Smart cloud health listed: with a market value of HK $15billion, SIG Jingwei and Jingxin fund are shareholders
- 【从 0 开始学微服务】【02】从单体应用走向服务化
- 在字符串中查找id值MySQL
- mysql怎么创建,删除,查看索引?
- Sample chapter of "uncover the secrets of asp.net core 6 framework" [200 pages /5 chapters]
- 基于NeRF的三维内容生成
- NPM instal reports agent or network problems
- 怎样重置火狐浏览器
- 如何将 @Transactional 事务注解运用到炉火纯青?
猜你喜欢
Sequoia China completed the new phase of $9billion fund raising
. Net ultimate productivity of efcore sub table sub database fully automated migration codefirst
What if does not match your user account appears when submitting the code?
.Net下极限生产力之efcore分表分库全自动化迁移CodeFirst
高瓴投的澳斯康生物冲刺科创板:年营收4.5亿 丢掉与康希诺合作
Smart cloud health listed: with a market value of HK $15billion, SIG Jingwei and Jingxin fund are shareholders
Master公式。(用于计算递归的时间复杂度。)
Four functions of opencv
明星企业普渡科技大裁员:曾募资超10亿 腾讯红杉是股东
[pytorch practice] write poetry with RNN
随机推荐
About IPSec
基于NeRF的三维内容生成
How does MySQL create, delete, and view indexes?
Image pixel read / write operation
Leetcode skimming: binary tree 21 (verifying binary search tree)
【无标题】
Aosikang biological sprint scientific innovation board of Hillhouse Investment: annual revenue of 450million yuan, lost cooperation with kangxinuo
Leetcode brush questions: binary tree 19 (merge binary tree)
[statistical learning methods] learning notes - Chapter 4: naive Bayesian method
博文推荐|Apache Pulsar 跨地域复制方案选型实践
What if does not match your user account appears when submitting the code?
认养一头牛冲刺A股:拟募资18.5亿 徐晓波持股近40%
Aike AI frontier promotion (7.7)
Session
ip2long之后有什么好处?
企业级自定义表单引擎解决方案(十二)--体验代码目录结构
免费手机号码归属地API查询接口
2022A特种设备相关管理(锅炉压力容器压力管道)模拟考试题库模拟考试平台操作
ISPRS2021/遥感影像云检测:一种地理信息驱动的方法和一种新的大规模遥感云/雪检测数据集
在字符串中查找id值MySQL