Application of Asp.net Regular Expression

Source: Internet
Author: User

1. Balanced group/recursive match
(? 'Group') Name the content corresponding to the group and press the stack count;
(? '-Group') returns the corresponding content named 'group' to the stack count.
(?!) Assertion with Zero Width and negative direction, attempts to match always fail because there is no suffix expression
Regular Expression 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 result: "1": ["1", "1-1", "1-2"],

Comments: This is a good one. To retrieve the latest one ].

2. Zero-width assertion
(? = Exp) match the position before exp
(? <= Exp) match the position behind exp
(?! Exp) the position behind the matching is not the exp position.
(? <! Exp) match the position not above exp
Regular Expression example:
(? <= <(\ W +)> ).*(? = <\/\ 1>)

Test data:
<Li> <a href = "# updatelog"> Update records </a> </LI>

Comparison result: <a href = "# updatelog"> Update record </a>

Comments: This is a good one. You can get the start and end, but it cannot be in the <A> .... </a> <A>... </a> the hmtl does not allow <A> to appear again <A>. If it is a DIV, it must be written as follows.

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

<Div class = "NOTE"> AAA <div> other available test tools: </div> BBBB </div> <a href = "www. *****. com "> gogogo </a> </div>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.