当前位置:网站首页>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
边栏推荐
- Leetcode skimming: binary tree 20 (search in binary search tree)
- How to apply @transactional transaction annotation to perfection?
- HZOJ #236. Recursive implementation of combinatorial enumeration
- [Q&A]AttributeError: module ‘signal‘ has no attribute ‘SIGALRM‘
- What if the xshell evaluation period has expired
- Day26 IP query items
- Session
- [statistical learning method] learning notes - logistic regression and maximum entropy model
- 认养一头牛冲刺A股:拟募资18.5亿 徐晓波持股近40%
- Sorting, dichotomy
猜你喜欢
Leetcode brush question: binary tree 24 (the nearest common ancestor of binary tree)
2022 examination questions and online simulation examination for safety production management personnel of hazardous chemical production units
Cookie
通过Keil如何查看MCU的RAM与ROM使用情况
博文推荐|Apache Pulsar 跨地域复制方案选型实践
Master公式。(用于计算递归的时间复杂度。)
How to continue after handling chain interruption / sub chain error removed from scheduling
ISPRS2021/遥感影像云检测:一种地理信息驱动的方法和一种新的大规模遥感云/雪检测数据集
.Net下極限生產力之efcore分錶分庫全自動化遷移CodeFirst
2022聚合工艺考试题模拟考试题库及在线模拟考试
随机推荐
通讯协议设计与实现
图像像素读写操作
test
CMU15445 (Fall 2019) 之 Project#2 - Hash Table 详解
处理链中断后如何继续/子链出错removed from scheduling
MySQL导入SQL文件及常用命令
@What is the difference between resource and @autowired?
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
About IPSec
PHP调用纯真IP数据库返回具体地址
HZOJ #240. Graphic printing IV
2022-07-07 Daily: Ian Goodfellow, the inventor of Gan, officially joined deepmind
xshell评估期已过怎么办
NPM instal reports agent or network problems
[pytorch practice] use pytorch to realize image style migration based on neural network
Shortcut key of Bash
Several ways to clear floating
Cookie
初学XML