当前位置:网站首页>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 .
边栏推荐
- MVC three-tier architecture
- Three effective strategies for the transformation of data supply chain to be coordinated and successful
- 第1章 需求分析与ssm环境准备
- 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
- Real time voice quality monitoring
- Chapter 1 requirements analysis and SSM environment preparation
- 实数范围内的求模(求余)运算:负数求余究竟怎么求
- 第1章 开发第一个restful应用
- 告别宽表,用 DQL 成就新一代 BI
- Simple SQL optimization
猜你喜欢

The place where the dream begins ---- first knowing C language (2)

04 traditional synchronized lock

Pytorch学习记录(二):张量

Azure synapse analytics Performance Optimization Guide (3) -- optimize performance using materialized views (Part 2)

DHCP, VLAN, NAT, large comprehensive experiment

Dynamic SQL

04-传统的Synchronized锁

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

Part II - C language improvement_ 8. File operation

C language array
随机推荐
The nature and proof of the center of gravity of [mathematics] tree
[C language] array
14_ Basic list
12_ Binding style
银河证券网上开户佣金,网上客户经理开户安全吗
Chapter 1 requirements analysis and SSM environment preparation
29、 Implementation of xv6 file system (GDB tracks mkfs, buffer cache and log)
百度网址收录
【不积跬步无以至千里】统计日志指定时间段内的关键词
Simple SQL optimization
08_ Event modifier
My SQL is OK. Why is it still so slow? MySQL locking rules
Sign up now | frontier technology exploration: how to make spark stronger and more flexible
Number that cannot be bought
Part II - C language improvement_ 13. Recursive function
使用AW9523B芯片驱动16路LED时,LED出现误点亮的问题
[shader realizes swaying effect _shader effect Chapter 4]
Easily implement seckill system with redis! (including code)
In depth interpretation of the investment logic of the consortium's participation in the privatization of Twitter
Modulo (remainder) operation in the range of real numbers: how to find the remainder of negative numbers