当前位置:网站首页>Regular expression introduction and some syntax
Regular expression introduction and some syntax
2022-06-26 00:16:00 【Big dream_ Thousands of autumn】
Regular expression introduction and some syntax
Simple translation of characters
Symbol | meaning |
---|---|
\n | Represents a newline character |
\t | For tab |
\\ | representative \ In itself |
\^,\$,\(,\),\{,\},\?,\+,\*,|,\[,\] | Match the symbols themselves |
Standard character set
Can and Multiple characters Matching expression
Be case sensitive , Capital letters mean the opposite
Symbol | meaning |
---|---|
\d | Any number ,0~9 Any one of |
\D | The digital |
\w | Any alphanumeric or underscore ,A-Z,a-z,0~9,_ |
\W | Any character except alphanumeric underscores |
\s | Including Spaces 、 tabs 、 Any one of white space characters such as line feed |
\S | Except for the space 、 tabs 、 Any character other than the newline character |
. | The decimal point can match any character , But it doesn't match the newline character , If you want to match, include \n All the characters in , It's usually used [\s\S] |
Custom character set
[] Square brackets match : Can match any character in the formula bracket
expression | Matching character |
---|---|
[[email protected]] | matching a perhaps b perhaps @ perhaps 5 |
^ab] | Match except a,b Any character other than |
[f-k] | matching f To k Any character between , Include f and k |
[^A-F0-3] | Match except A ~ F,0 ~ 3 Any character other than |
- stay [ ] in ^ It means to take an objection .
- Special symbols for regular expressions , Enclosed in square brackets , Is to go to the special significance , except ^ and - outside .
- Standard character set , Except that the decimal point in brackets will lose its special meaning , Others don't . [\dab], Match numbers or a,b
quantifiers
A special symbol that modifies the number of matches
expression | meaning |
---|---|
{n} | The expression repeats n Time , Include n |
{m,n} | The expression repeats at least m Time , Repeat at most n Time , Include m and n |
{m,} | The expression repeats at least m Time , Include m |
? | Match expression 0 Time or 1 Time , amount to {0,1} |
+ | The expression appears at least once , amount to {1,} |
* | The expression does not appear or occurs any time , amount to {0,} |
- Greedy mode : The more characters you match, the better , Default . For example, if the following figure is written as c{2,6}, It will match one cccccc.
- Non greedy model : Is to add a after the quantifier ? Number . Or the picture below , It's written in c{2,6}?, It will match to 3 individual cc
If it's continuous 6 individual c, Use expressions c{2,3}, Will match to the 2 individual ccc, This is because it matches the first one ccc Time will Recount .
Character boundary
Symbol | meaning |
---|---|
^ | What to start with |
$ | To what end |
\b | The left and right boundaries are not all \w , That is, there are not all letters on the left and right , Numbers , Underline |
Regular matching patterns
- Ignore case mode
- One way mode : The entire text is treated as a string , There is only one beginning , An end .
- Multi line mode : Each line is a string , There's a beginning and an end .
Selector or grouping
expression | effect |
---|---|
| | Between left and right expressions or Relationship , Match left , Or on the right |
() | Capture group 1. At the time of being decorated with matching times , Expressions in parentheses can be decorated as a whole .2. Time to get the matching result , The expression in parentheses matches The content can be obtained separately |
backreferences : Each pair of () A number will be assigned , Use () Capture of from... According to the left parenthesis 1 Start AutoNumber .
By reverse reference , You can reference strings that have been captured by grouping , Here's the picture : The expression in parentheses means that two letters are matched , hinder \1 Said to () References to the contents of , namely () Match to go,\1 Quote again go, At this time, what this regularization needs is gogo
Assertion
- Match only subexpressions , The matching content is not included in the matching result
- This position should meet certain conditions
expression | meaning |
---|---|
(?=exp) | Assert where it appears The back can be Match to expression exp |
(?<=exp) | Assert where it appears Front can Match to expression exp |
(?!exp) | Assert where it appears Not in the back Match to expression exp |
(?<!exp) | Assert where it appears Not in front Match to expression exp |
for example : Assert that you can match with ing The characters of
边栏推荐
- Use js to obtain the last quarter based on the current quarter
- How postman tests interfaces that require login
- DNS复习
- [advanced ROS] Lecture 1 Introduction to common APIs
- Some basic uses of mongodb
- mysql 主从复制
- Redux workflow + complete code of small examples
- Use Coe_ load_ sql_ profile. SQL fixed execution plan
- Installation of third-party library iGraph for social network visualization
- 10.3.1、FineBI_ Installation of finebi
猜你喜欢
MySQL master-slave replication
Thrift入门学习
DNS复习
Explain in detail the three types of local variables, global variables and static variables
10.4.1、數據中臺
idea设置mapper映射文件的模板
10.4.1 data console
[advanced ROS] Lecture 1 Introduction to common APIs
把控元宇宙产业的发展脉络
Literature research (IV): Hourly building power consumption prediction based on case-based reasoning, Ann and PCA
随机推荐
86.(cesium篇)cesium叠加面接收阴影效果(gltf模型)
Reading notes on how to connect the network - hubs, routers and routers (III)
Explain the synchronize keyword
安装PSU的时候/usr/bin/ld:warning: -z lazyload ignore
Simulink求解器综合介绍
The problem of low video memory in yolov5 accelerated multi GPU training
Record some CF questions
10.2.3、Kylin_ The dimension is required for kylin
10.3.1、FineBI_ Installation of finebi
yolov5 提速多GPU训练显存低的问题
MySQL master-slave replication
anchor free dection简介
《SQL优化核心思想》
SQL中只要用到聚合函数就一定要用到group by 吗?
EBS r12.2.0 to r12.2.6
How to bypass SSL authentication
js数组中修改元素的方法
[wechat official account H5] generates a QR code with parameters to enter the official account attention page to listen to user-defined menu bar for official account events (server)
Thrift getting started
Servlet response下载文件