asp.net Application of regular expression

Time:2021-4-23

1. Balanced group / recursive matching
(?’ Group ‘), which is called the corresponding content of group, and counts it on the stack;
(?’- Group ‘), and count the corresponding content named group out of the stack
(?!) Zero width negative look ahead assertion. Since there is no suffix expression, attempts to match always fail
Regular example:
,{0,1}”5″:\[[^\[\]]*(((?’Open’\[)[^\[\]]*)+((?’-Open’\])[^\[\]]*)+)*(?(Open)(?!))\],{0,1}
Test data:
{“0”:[“0″,”0-1″,”0-2″],”1”:[“1″,”1-1″,”1-2″],”2”:[“2″,”2-1″,”2-2″],”3”:[“3″,”3-1″,”3-2″],”4”:[“4″,”4-1″,”4-2″],”5”:[“5″,”5-1″,”5-2”]}
Comparison results: “1”: [“1”, “1-1”, “1-2”],

Comment: This is very good. It can achieve the effect of taking out the nearest one

2. Zero width assertion
(?= Exp) matches the position in front of exp
(?<= Exp) matches the position after exp
(?! Exp) is not followed by the location of exp
(?<! Exp) matches the position not in front of exp
Regular example:
(?<=<(\w+)>).*(?=<\/\1>)

Test data:
<li>Update record < a</a></li>

The comparison results were as follows: the records were updated in the following way</a>

Comment: This is very good. You can take the beginning and end, but you can’t see < a >… < / a > in < a >… < / a > again. Fortunately, hmtl doesn’t let < a > appear in < a > again. If it’s like div, you have to write it like this.

<[^<>]*(((?’Open'<)[^<>]*)+((?’-Open’>)[^<>]*)+)*(?(Open)(?!))>

< div > AAA < div > other available testing tools: < / div > BBBB < / div > < div > < a