当前位置:网站首页>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 
边栏推荐
猜你喜欢

EBS R12.2.0升级到R12.2.6

Literature research (III): overview of data-driven building energy consumption prediction models

Ora-01153: incompatible media recovery activated

EasyConnect连接后显示未分配虚拟地址

Shenzhen Taipower: the way of "communication" of the United Nations

Common problems encountered when creating and publishing packages using NPM

86.(cesium篇)cesium叠加面接收阴影效果(gltf模型)

删库跑路、“投毒”、改协议,开源有哪几大红线千万不能踩?

When installing PSU /usr/bin/ld:warning: -z lazload ignore

11.1.1、flink概述_flink概述
随机推荐
Record some CF questions
Shenzhen Taipower: the way of "communication" of the United Nations
JS to input the start time and end time, output the number of seasons, and print the corresponding month and year
When installing PSU /usr/bin/ld:warning: -z lazload ignore
Recommended system design
10.4.1、数据中台
dhcp复习
Core ideas of SQL optimization
19c安装psu 19.12
Linux下搭建集群环境(2)-----------linux下安装Mysql
Reading notes on how to connect the network - hubs, routers and routers (III)
no_ Expand and use_ concat
被新冠后遗症困住15个月后,斯坦福学霸被迫缺席毕业典礼,现仍需每天卧床16小时:我本该享受20岁的人生啊...
快手实时数仓保障体系研发实践
11.1.1、flink概述_flink概述
What is micro service
mysql 主从复制
Redis之内存淘汰机制
Research and development practice of Kwai real-time data warehouse support system
小红书微服务框架及治理等云原生业务架构演进案例