当前位置:网站首页>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
边栏推荐
- .Net下极限生产力之efcore分表分库全自动化迁移CodeFirst
- 3D content generation based on nerf
- 【无标题】
- 【无标题】
- What are the benefits of ip2long?
- ICLR 2022 | pre training language model based on anti self attention mechanism
- Layer pop-up layer closing problem
- . Net ultimate productivity of efcore sub table sub database fully automated migration codefirst
- 2022A特种设备相关管理(锅炉压力容器压力管道)模拟考试题库模拟考试平台操作
- visual stdio 2017关于opencv4.1的环境配置
猜你喜欢
关于 appium 启动 app 后闪退的问题 - (已解决)
[statistical learning method] learning notes - support vector machine (Part 2)
. Net ultimate productivity of efcore sub table sub database fully automated migration codefirst
处理链中断后如何继续/子链出错removed from scheduling
红杉中国完成新一期90亿美元基金募集
[爬虫]使用selenium时,躲避脚本检测
AUTOCAD——大于180度的角度标注、CAD直径符号怎么输入?
Day-15 common APIs and exception mechanisms
Four functions of opencv
通过Keil如何查看MCU的RAM与ROM使用情况
随机推荐
有什么类方法或是函数可以查看某个项目的Laravel版本的?
明星企业普渡科技大裁员:曾募资超10亿 腾讯红杉是股东
云检测2020:用于高分辨率遥感图像中云检测的自注意力生成对抗网络Self-Attentive Generative Adversarial Network for Cloud Detection
2022聚合工艺考试题模拟考试题库及在线模拟考试
详解ThinkPHP支持的URL模式有四种普通模式、PATHINFO、REWRITE和兼容模式
.Net下极限生产力之efcore分表分库全自动化迁移CodeFirst
Day21 multithreading
Day-14 common APIs
图像像素读写操作
@What is the difference between resource and @autowired?
Sorting, dichotomy
红杉中国完成新一期90亿美元基金募集
Session
ACL 2022 | 序列标注的小样本NER:融合标签语义的双塔BERT模型
Leetcode skimming: binary tree 20 (search in binary search tree)
[Q&A]AttributeError: module ‘signal‘ has no attribute ‘SIGALRM‘
Day-20 file operation, recursive copy, serialization
图形对象的创建与赋值
HZOJ #240. 图形打印四
[crawler] avoid script detection when using selenium