9.1.6 Multiple matching items

Source: Internet
Author: User
The matches () method of the RegEx class can locate the matching item in the input string based on the given regular expression, and return the matching item as a single matching item. Each matching item is of the match type. The matches () method of the RegEx class has the following four overload methods. (1) RegEx. matches (string input); (2) RegEx. matches (string input, int startat); (3) RegEx. matches (string input, string pattern); (4) RegEx. matches (string input, string pattern, regexoptions options ). The input parameter specifies the input string, the pattern parameter specifies the regular expression, the startat parameter specifies the character location to start searching, and the options parameter specifies the matching option. The following code finds the matching item of the regular expression "/d +" in the string "0123456789abcd321bfr987. The regexmatches () method uses the matches () Static Method of the RegEx class. The matches () method creates a RegEx instance RegEx and uses the matches () instance method of the instance. /// <Summary> /// match the given expression /// </Summary> /// <returns> </returns> private string [] regexmatches () {string input = "0123456789abcd321bfr987"; string pattern = @ "/d +"; matchcollection matches = RegEx. matches (input, pattern); If (matches = NULL) return NULL; string [] result = new string [matches. count]; for (INT I = 0; I <result. length; I ++) {result [I] = matches [I]. value;} return result;} // <summary> // match the given expression // // </Summary> // <returns> </returns> private string [] matches () {string input = "0123456789abcd321bfr987"; string pattern = @ "/d + "; regEx = new RegEx (pattern); matchcollection matches = RegEx. matches (input); If (matches = NULL) return NULL; string [] result = new string [matches. count]; for (INT I = 0; I <result. length; I ++) {result [I] = matches [I]. value;} return result;} the following code is found in the string "abcdabcdedfgedfgwyz ". Find the matching item of the regular expression "[A-Z] +. In addition, the regexoptions. ignorecase option is enabled during the search process. The regexmatches () method uses the matches () Static Method of the RegEx class. The matches () method creates a RegEx instance RegEx and uses the matches () instance method of the instance. /// <Summary> /// match the given expression, with options /// </Summary> /// <returns> </returns> private string [] regexmatchesoptions () {string input = "abcdabcdedfgedfgwyz "; string Pattern = @ "[A-Z] +"; matchcollection matches = RegEx. matches (input, pattern, regexoptions. ignorecase); If (matches = NULL) return NULL; string [] result = new string [matches. count]; for (INT I = 0; I <result. length; I ++) {result [I] = matches [I]. value;} return result;} // <summary> // matches the given expression, with options /// </Summary> /// <returns> </returns> private string [] matchesoptions () {string input = "abcdabcdedfgedfgwyz "; string Pattern = @ "[A-Z] +"; RegEx = new RegEx (pattern, regexoptions. ignorecase); matchcollection matches = RegEx. matches (input); If (matches = NULL) return NULL; string [] result = new string [matches. count]; for (INT I = 0; I <result. length; I ++) {result [I] = matches [I]. value;} return result ;}

 

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.