当前位置:网站首页>Share a regular expression
Share a regular expression
2022-07-26 23:55:00 【Red blue red】
List of articles
One 、 Regular expressions
2022 year 7 month 14 Japan , Our group came across a regular expression , It feels quite complicated , At that time, everyone was baffled , Later, it took some time to figure it out . The regular expression is as follows :
/^(?:[^#<]*(<[wW]+>)[^>]*$)/
Readers who are interested can think for themselves first , Then continue to look at the following content .
Two 、 The analysis process
Usually you see a regular expression , To figure out the logic , A wave of simplification is needed first .
First look from left to right , A ^, Indicates the beginning of the qualification , Last $ Indicates a qualified end .
Then I saw in () In the ?:, What does that mean ? You need to know the following first :
() The content in itself represents capture packets , After the content is regularly recognized , Will be saved for future use . and
If this happens (?:), It means non capture packets , The only difference from capture grouping is , The matching values of non captured groups will not be saved , So for the server , Reduce a stored procedure , Reduce the consumption of resources , It can also improve the efficiency of regularization .
So for analyzing the regular expression itself , Is there any ?: It doesn't make any difference , You can simplify it for the first time :
/^([^#<]*(<[wW]+>)[^>]*$)/
Then look at [^#<], Don't be trapped. # Scared me. , Actually, after testing ,^#< and ^< There is no difference here , It means that they don't match <
So do the second simplification :
/^([^<]*(<[wW]+>)[^>]*$)/
Then do the third simplification , Obviously ,* The existence of can be completely ignored , Delete directly , So as to realize the third simplification :
/^([^<](<[wW]+>)[^>]$)/
Now look at the end $, There is no difference between putting it inside and outside the brackets , So just move it outside , Realize the fourth simplification :
/^([^<](<[wW]+>)[^>])$/
Now simplify again , Namely + Its function is to connect , You can delete , So do the fifth simplification as follows :
/^([^<](<[wW]>)[^>])$/
You can see , The parentheses in the middle mean , Only accept or these two situations .
The brackets on the left indicate , Can accept a non < Any character of , Note that yes , Not necessarily .
The bracket on the right is the same , Can accept a non > Any character of , Note that yes , Not necessarily .
Therefore, there can be countless people who conform to the rules , The core is to include or , The beginning and end can be followed by any character other than angle brackets .
Analysis complete , It can be used as follows php Try the code test :
<?php
$a=$_REQUEST['a'];
var_dump(Preg_match_all('/^(?:[^#<]*(<[wW]+>)[^>]*$)/',$a,$b));
echo '<br />';
?>
First, test the transmission parameters <w> and <W> as follows :

Try passing a non angle bracket character at any beginning and end :
succeed , It shows that the previous analysis is correct .
3、 ... and 、 Summary
This article will share with you a regular expression encountered in the work , I hope that's helpful .
边栏推荐
- Part II - C language improvement_ 6. Multidimensional array
- 2022.7.26-----leetcode.1206
- Tensorflow2.0 deep learning simple tutorial of running code
- Distributed lock and its implementation
- 华测RTK采集的GPX数据如何带属性转出kml、shp进行后续的管理和分析
- 15_ Key function and principle
- [C language] classic recursion problem
- 第二部分—C语言提高篇_7. 结构体
- Paging plug-in -- PageHelper
- 【不积跬步无以至千里】统计日志指定时间段内的关键词
猜你喜欢

Sign up now | frontier technology exploration: how to make spark stronger and more flexible

np.transpose & np.expand_dims

Problems and solutions encountered in using nextline(), nextint() and next() in scanner

Chapter 1 requirements analysis and SSM environment preparation
![[shader realizes shine effect _shader effect Chapter 3]](/img/ea/6c14f682e6157a96c1877d99c9f7d3.png)
[shader realizes shine effect _shader effect Chapter 3]

Meeting OA my meeting

嵌入式系统移植【8】——设备树和根文件系统移植

华测RTK采集的GPX数据如何带属性转出kml、shp进行后续的管理和分析

Use Arthas to locate online problems

Everything you should know about wearable NFT!
随机推荐
Embedded system migration [8] - device tree and root file system migration
Can the stock account opening commission be adjusted? Is it safe to open an account on your mobile phone
第二部分—C语言提高篇_12. 动/精态库的封装和使用
Part II - C language improvement_ 5. Bit operation
In depth interpretation of the investment logic of the consortium's participation in the privatization of Twitter
In simple terms, cchart's daily lesson - Lesson 59 of happy high school 4 comes to the same end by different ways, and the C code style of the colorful interface library
[C language] array
ES6新特性
push to origin/master was rejected 错误解决方法
The nature and proof of the center of gravity of [mathematics] tree
华测RTK采集的GPX数据如何带属性转出kml、shp进行后续的管理和分析
关于可穿戴式NFT你应该知道的一切!
Three effective strategies for the transformation of data supply chain to be coordinated and successful
15_ Key function and principle
11_ Weather case - monitoring properties
文件上传到OSS文件服务器
13_ conditional rendering
Tensorflow2.0 深度学习运行代码简单教程
Pytorch学习记录(二):张量
Question 141 of Li Kou: circular linked list