当前位置:网站首页>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 .
边栏推荐
- Three effective strategies for the transformation of data supply chain to be coordinated and successful
- Thousands of tiles' tilt model browsing speeds up, saying goodbye to the embarrassment of jumping out one by one
- 09_ Keyboard events
- 带你熟悉云网络的“电话簿”:DNS
- 买不到的数目
- Use Arthas to locate online problems
- Azure synapse analytics Performance Optimization Guide (3) -- optimize performance using materialized views (Part 2)
- Silicon Valley class lesson 6 - Tencent cloud on demand management module (I)
- Dajiang Zhitu and CC have produced multiple copies of data. How to combine them into one and load them in the new earth map
- MVC three-tier architecture
猜你喜欢

Silicon Valley class lesson 7 - Tencent cloud on demand management module (2)

第1章 需求分析与ssm环境准备
![[H5 bottom scrolling paging loading]](/img/2c/fb8dd8a7d985392450ad7d3b70016c.png)
[H5 bottom scrolling paging loading]

04 traditional synchronized lock

Meeting OA my meeting
![[shaders realize distorted outline effect _shader effect Chapter 2]](/img/b3/ab28039cce2521ff1d59f0de6bf852.png)
[shaders realize distorted outline effect _shader effect Chapter 2]

Silicon Valley class lesson 6 - Tencent cloud on demand management module (I)

百度网址收录

Practice of intelligent code reconstruction of Zhongyuan bank

Sign up now | frontier technology exploration: how to make spark stronger and more flexible
随机推荐
[C language] array
Typescript notes
Paging plug-in -- PageHelper
3 esp8266 nodemcu network server
Azure Synapse Analytics 性能优化指南(4)——使用结果集缓存优化性能
[Luogu] p2341 popular cattle
The NFT market pattern has not changed. Can okaleido set off a new round of waves?
Bid farewell to wide tables and achieve a new generation of Bi with DQL
Related functions of strings
Silicon Valley class lesson 5 - Tencent cloud object storage and course classification management
2022.7.26-----leetcode.1206
Number that cannot be bought
大疆智图、CC生产了多份数据,如何合并为一份在图新地球进行加载
Thousands of tiles' tilt model browsing speeds up, saying goodbye to the embarrassment of jumping out one by one
股票开户佣金是否可以调整?手机上开户安不安全
Chapter 3 cross domain issues
第1章 开发第一个restful应用
简单的SQL优化
Dynamic SQL
Everything you should know about wearable NFT!