Regular expression tips (constantly updated ...)

Source: Internet
Author: User

We use regular expressions most of the time to do input validation, that is, to match only one qualifying result, but if we parse some special format of the text, we need multiple matching results, then how to get multiple matching results? Here are two ways to do this:

Method One:

Using the Matches method, get the matchcollection result, and traverse the matchcollection to get a matching result.

string equ = @ "\w*@.*"new Regex (@ "\d+?\d+_?\d*"in//  using Matches method  {    Console.WriteLine (m.value);}

Method Two:

Using the NextMatch method, when the match succeeds, continue to match down.

// You can also use the match method to match the first  while (m.success) {    Console.WriteLine (m.value);     // use NextMatch to get the next }

Regular expression tips (constantly updated ...)

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.