C # Regular Extraction Small example

Source: Internet
Author: User

Common grouping Syntax
category Code/Syntax Description
Capture (exp) Match exp, and capture text into an automatically named group
(? <name>exp) Match exp, and capture the text to a group named name, or you can write (? ') Name ' exp ')
(?: EXP) Matches exp, does not capture matching text, and does not assign group numbers to this group
0 Wide Assertion (? =exp) Match the position of the exp front
(? <=exp) Match the position after exp
(?! Exp Match the position followed by the exp.
(? <!exp) Match a location that is not previously exp
Comments (? #comment) This type of grouping does not have any effect on the processing of regular expressions, and is used to provide comments for people to read

Extract Payaccno in the middle of the account string input = @ "        <payaccno>6227000000000000001</payaccno>        <payaccname > Zhang San </payaccname>        <payaccno>6227000000000000002</payaccno>        <payaccname> John Doe </payaccname>                       "; Regex reg = new Regex (@ "(?<=<payaccno>) (\d+) (?=</payaccno>) +"), var matches = Reg. Matches (input); string result = ""; foreach (var m in Matches) {    result + = m + ",";} result = result. TrimEnd (', ');//Result: 6227007201840000001,6227007201840000002

C # Regular Extraction Small example

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.