Summary of the C # Regular Expression matchcollection class

Source: Internet
Author: User

Understanding matchcollectionClass

Indicates that the regular expression pattern is applied to the set of successful matches found in the input string in iterative mode.

Namespace: system. Text. regularexpressions

Attribute: count indicates the number of matched items.

Method: tostring indicates the string of the current object.

Note:

The set is unchangeable (read-only) and there is no public constructor. The RegEx. Matches method returns the matchcollection object.

Introduction from Microsoft――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

 

C #Matchcollection in Regular ExpressionsClass usage

 

The matchcollection class indicates a successful read-only set of non-overlapping matches. The matchcollection instance is composed of RegEx. the following example shows how to find all the matches specified in RegEx in the input string and fill in matchcollection.

Two examples are provided:

 

1,

  matchcollection MC; RegEx r  =  New  RegEx ("   match  "   ); MC  = R. matches ( "  matchcollectionregexmatchs  "   );   for  ( int  I =  0 ; I 
  
   ) {response. write (MC [I]. value  + 
    " 
    pos:  
    " + Mc [I]. index. tostring () + 
    " 
    
" ) ;}

 

The instance runs as follows:

Match pos: 0

Match pos: 20

2,

 Public   Static   String Geturl ( String  Text ){  String Pattern = @"  (HTTP | FTP | https): \ // [\ W] + (. [\ W] +) ([\ W \-\.,@? ^ = % & Amp ;:/~ \ + #] * [\ W \-\@? ^ = % & Amp ;/~ \ + #])  "  ; Matchcollection matchs; matchs = RegEx. Matches (text, pattern, regexoptions. ignorecase |Regexoptions. Compiled );  Foreach (Match m In  Matchs) {text = Text. Replace (M. tostring (), "  <A target = \ "_ new \" href = \"  " + M. tostring () + "  \ ">  " + M. tostring () + "  </A>  "  );} Return  Text ;} 

 

 

Mark.

 

--------------------------------------------------------------------

Other commonC #Regular Expression class:

 

RegExClass indicates an unchangeable (read-only) regular expression. It also contains various static methods that allow other regular expression classes to be used without explicitly creating instances of other classes.

MatchClass indicates the result of the regular expression matching operation. Whether the match. Success match of the Match Class is successful. Match. Index returns the first matched position.

MatchcollectionClass indicates the sequence of successful [non-overlapping] matching items. The matchcollection instance is returned by the RegEx. Matches method.

GroupcollectionClass indicates the set of captured groups and returns the set of captured groups in a single match. Groupcollection instances are returned in the Set returned by the match. Groups attribute.

CapturecollectionClass indicates the sequence of the captured substring and returns the capture set executed by a single capture group. Because of the qualifier, the capture group can capture multiple strings in a single match. The captures attribute (the object of the capturecollection class) is provided as a member of the match and group classes to facilitate access to the collection of captured substrings.

GroupClass indicates the result from a single capture group. Because a group can capture zero, one, or more strings (using a qualifier) in a single match, it contains a set of capture objects. Because group inherits from capture, you can directly access the final captured substring (the Group instance itself is equivalent to the last entry of the Set returned by the captures attribute ).

CaptureClass contains the results captured by a single subexpression.

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.