1 //------------------------------------------------------------------------------
2 // <copyright file="RegexGroup.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
7 // Group represents the substring or substrings that
8 // are captured by a single capturing group after one
9 // regular expression match.
11 namespace System.Text.RegularExpressions {
12 using System.Security.Permissions;
16 /// represents the results from a single capturing group. A capturing group can
17 /// capture zero, one, or more strings in a single match because of quantifiers, so
18 /// Group supplies a collection of Capture objects.
23 public class Group : Capture {
24 // the empty group object
25 internal static Group _emptygroup = new Group(String.Empty, new int[0], 0);
28 internal int _capcount;
29 internal CaptureCollection _capcoll;
31 internal Group(String text, int[] caps, int capcount)
33 : base(text, capcount == 0 ? 0 : caps[(capcount - 1) * 2],
34 capcount == 0 ? 0 : caps[(capcount * 2) - 1]) {
41 * True if the match was successful
44 /// <para>Indicates whether the match is successful.</para>
48 return _capcount != 0;
53 * The collection of all captures for this group
57 /// Returns a collection of all the captures matched by the capturing
58 /// group, in innermost-leftmost-first order (or innermost-rightmost-first order if
59 /// compiled with the "r" option). The collection may have zero or more items.
62 public CaptureCollection Captures {
65 _capcoll = new CaptureCollection(this);
72 * Convert to a thread-safe object by precomputing cache contents
76 /// a Group object equivalent to the one supplied that is safe to share between
77 /// multiple threads.</para>
81 [HostProtection(Synchronization=true)]
83 static public Group Synchronized(Group inner) {
85 static internal Group Synchronized(Group inner) {
88 throw new ArgumentNullException("inner");
90 // force Captures to be computed.
92 CaptureCollection capcoll;
95 capcoll = inner.Captures;
97 if (inner._capcount > 0)