当前位置:网站首页>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
边栏推荐
- - Oui. Migration entièrement automatisée de la Sous - base de données des tableaux d'effets sous net
- 企业级自定义表单引擎解决方案(十二)--体验代码目录结构
- [statistical learning methods] learning notes - Chapter 4: naive Bayesian method
- 2022聚合工艺考试题模拟考试题库及在线模拟考试
- How to reset Google browser? Google Chrome restore default settings?
- 非分区表转换成分区表以及注意事项
- Talk about four cluster schemes of redis cache, and their advantages and disadvantages
- 关于 appium 启动 app 后闪退的问题 - (已解决)
- Leetcode skimming: binary tree 25 (the nearest common ancestor of binary search tree)
- . Net ultimate productivity of efcore sub table sub database fully automated migration codefirst
猜你喜欢

Cookie

数据库安全的重要性

.Net下极限生产力之efcore分表分库全自动化迁移CodeFirst

HZOJ #240. Graphic printing IV

2022A特种设备相关管理(锅炉压力容器压力管道)模拟考试题库模拟考试平台操作

Leetcode skimming: binary tree 27 (delete nodes in the binary search tree)
![[statistical learning method] learning notes - support vector machine (Part 2)](/img/bc/bb4f809ff434fabc10f8e97f592fa7.png)
[statistical learning method] learning notes - support vector machine (Part 2)

如何将 @Transactional 事务注解运用到炉火纯青?

Session

红杉中国完成新一期90亿美元基金募集
随机推荐
Sequoia China completed the new phase of $9billion fund raising
2022 polymerization process test question simulation test question bank and online simulation test
环境配置篇
SSM框架搭建的步骤
ICLR 2022 | pre training language model based on anti self attention mechanism
ACL 2022 | small sample ner of sequence annotation: dual tower Bert model integrating tag semantics
高瓴投的澳斯康生物冲刺科创板:年营收4.5亿 丢掉与康希诺合作
Go语言学习笔记-结构体(Struct)
Leetcode brush questions: binary tree 19 (merge binary tree)
2022a special equipment related management (boiler, pressure vessel and pressure pipeline) simulated examination question bank simulated examination platform operation
Grep of three swordsmen in text processing
[learn micro services from 0] [02] move from single application to service
Connect to blog method, overload, recursion
Several ways to clear floating
《ASP.NET Core 6框架揭秘》样章[200页/5章]
详解ThinkPHP支持的URL模式有四种普通模式、PATHINFO、REWRITE和兼容模式
明星企业普渡科技大裁员:曾募资超10亿 腾讯红杉是股东
Lingyunguang of Dachen and Xiaomi investment is listed: the market value is 15.3 billion, and the machine is implanted into the eyes and brain
通讯协议设计与实现
Day21 multithreading