Sideway
output.to from Sideway
Draft for Information Only

Content

Regular Expression Result
 Capture Class
  Properties
  Methods
  Remarks
  Applies to
  See also
 CaptureCollection Class
  Properties
  Methods
  Extension Methods
  Remarks
  Applies to
  See also
 Group Class
  Properties
  Methods
  Remarks
  Applies to
 GroupCollection Class
  Properties
  Methods
  Extension Methods
  Remarks
  Applies to
  See also
 Examples
 Source/Reference

Regular Expression Result

The results of the regular expression engine of .NET framework can be accessed by Capture Class, CaptureCollection Class, Group Class, GroupCollection Class, Match Class, MatchCollection Class. A regular expression pattern is considered as the zero natural Group. A bracket regular expression pattern is a defined Group. All groups are collected as a GroupCollection. Capture is the basic captured unit of regular expressions for both Match and Group to represent a single successful subexpression capture. The Capture of one or more occurrences of a bracket group is collected as a MatchCollection. However, the MatchCollection is defined as the set of Captures made by a sngle capturing Group.

Capture Class

Represents the results from a single successful subexpression capture.

NamespaceSystem.Text.RegularExpressions AssembliesSystem.Text.RegularExpressions.dll, System.dll, netstandard.dll
[System.Serializable]
public class Capture

Properties

Index The position in the original string where the first character of the captured substring is found.
Length Gets the length of the captured substring.
Value Gets the captured substring from the input string.

Methods

Equals(Object) Determines whether the specified object is equal to the current object. (Inherited from Object)
GetHashCode() Serves as the default hash function. (Inherited from Object)
GetType() Gets the Type of the current instance. (Inherited from Object)
MemberwiseClone() Creates a shallow copy of the current Object. (Inherited from Object)
ToString() Retrieves the captured substring from the input string by calling the Value property.

Remarks

  • A Capture object is immutable and has no public constructor. Instances are returned through the CaptureCollection object, which is returned by the Match.Captures and Group.Captures properties. However, the Match.Captures property provides information about the same match as the Match object. If you do not apply a quantifier to a capturing group, the Group.Captures property returns a CaptureCollection with a single Capture object that provides information about the same capture as the Group object. If you do apply a quantifier to a capturing group, the Group.Index, Group.Length, and Group.Value properties provide information only about the last captured group, whereas the Capture objects in the CaptureCollection provide information about all subexpression captures. The example provides an illustration.

Applies to

.NET Framework: 4.8, 4.7.2, 4.7.1, 4.7, 4.6.2, 4.6.1, 4.6, 4.5.2, 4.5.1, 4.5, 4.0, 3.5, 3.0, 2.0, 1.1

See also

  • CaptureCollection

CaptureCollection Class

Represents the set of captures made by a single capturing group.

NamespaceSystem.Text.RegularExpressions AssembliesSystem.Text.RegularExpressions.dll, System.dll, netstandard.dll
[System.Serializable]
public class CaptureCollection : System.Collections.ICollection

Properties

Count Gets the number of substrings captured by the group.
IsReadOnly Gets a value that indicates whether the collection is read only.
IsSynchronized Gets a value that indicates whether access to the collection is synchronized (thread-safe).
Item[Int32] Gets an individual member of the collection.
SyncRoot Gets an object that can be used to synchronize access to the collection.

Methods

CopyTo(Array, Int32) Copies all the elements of the collection to the given array beginning at the given index.
Equals(Object) Determines whether the specified object is equal to the current object. (Inherited from Object)
GetEnumerator() Provides an enumerator that iterates through the collection.
GetHashCode() Serves as the default hash function. (Inherited from Object)
GetType() Gets the Type of the current instance. (Inherited from Object)
MemberwiseClone() Creates a shallow copy of the current Object. (Inherited from Object)
ToString() Returns a string that represents the current object. (Inherited from Object)

Extension Methods

Cast<TResult>(IEnumerable) Casts the elements of an IEnumerable to the specified type.
OfType<TResult>(IEnumerable) Filters the elements of an IEnumerable based on a specified type.
AsParallel(IEnumerable) Enables parallelization of a query.
AsQueryable(IEnumerable) Converts an IEnumerable to an IQueryable.

Remarks

  • The collection is immutable (read-only) and has no public constructor. The CaptureCollection object contains one or more Capture objects.
  • Instances of the CaptureCollection class are returned by the following properties:
    • The Group.Captures property. Each member of the collection represents a substring captured by a capturing group. If a quantifier is not applied to a capturing group, the CaptureCollection includes a single Capture object that represents the same captured substring as the Group object. If a quantifier is applied to a capturing group, the CaptureCollection includes one Capture object for each captured substring, and the Group object provides information only about the last captured substring.
    • The Match.Captures property. In this case, the collection consists of a single Capture object that provides information about the match as a whole. That is, the CaptureCollection object provides the same information as the Match object.
    To iterate through the members of the collection, you should use the collection iteration construct provided by your language (such as foreach in C# and For Each…Next in Visual Basic) instead of retrieving the enumerator that is returned by the GetEnumerator method.

Applies to

.NET Framework: 4.8, 4.7.2, 4.7.1, 4.7, 4.6.2, 4.6.1, 4.6, 4.5.2, 4.5.1, 4.5, 4.0, 3.5, 3.0, 2.0, 1.1

See also

  • Capture
  • Group

Group Class

Represents the results from a single capturing group.

NamespaceSystem.Text.RegularExpressions AssembliesSystem.Text.RegularExpressions.dll, System.dll, netstandard.dll
[System.Serializable]
public class Group : System.Text.RegularExpressions.Capture

Properties

Captures Gets a collection of all the captures matched by the capturing group, in innermost-leftmost-first order (or innermost-rightmost-first order if the regular expression is modified with the RightToLeft option). The collection may have zero or more items.
Index The position in the original string where the first character of the captured substring is found. (Inherited from Capture)
Length Gets the length of the captured substring. (Inherited from Capture)
Name Returns the name of the capturing group represented by the current instance.
Success Gets a value indicating whether the match is successful.
Value Gets the captured substring from the input string. (Inherited from Capture)

Methods

Equals(Object) Determines whether the specified object is equal to the current object. (Inherited from Object)
GetHashCode() Serves as the default hash function. (Inherited from Object)
GetType() Gets the Type of the current instance. (Inherited from Object)
MemberwiseClone() Creates a shallow copy of the current Object. (Inherited from Object)
Synchronized(Group) Returns a Group object equivalent to the one supplied that is safe to share between multiple threads.
ToString() Retrieves the captured substring from the input string by calling the Value property. (Inherited from Capture)

Remarks

  • A capturing group can capture zero, one, or more strings in a single match because of quantifiers. (For more information, see Quantifiers.) All the substrings matched by a single capturing group are available from the Group.Captures property. Information about the last substring captured can be accessed directly from the Value and Index properties. (That is, the Group instance is equivalent to the last item of the collection returned by the Captures property, which reflects the last capture made by the capturing group.)

Applies to

.NET Framework: 4.8, 4.7.2, 4.7.1, 4.7, 4.6.2, 4.6.1, 4.6, 4.5.2, 4.5.1, 4.5, 4.0, 3.5, 3.0, 2.0, 1.1

GroupCollection Class

Returns the set of captured groups in a single match.

NamespaceSystem.Text.RegularExpressions AssembliesSystem.Text.RegularExpressions.dll, System.dll, netstandard.dll
[System.Serializable]
public class GroupCollection : System.Collections.ICollection

Properties

Count Returns the number of groups in the collection.
IsReadOnly Gets a value that indicates whether the collection is read-only.
IsSynchronized Gets a value that indicates whether access to the GroupCollection is synchronized (thread-safe).
Item[Int32] Enables access to a member of the collection by integer index.
Item[String] Enables access to a member of the collection by string index.
SyncRoot Gets an object that can be used to synchronize access to the GroupCollection.

Methods

CopyTo(Array, Int32) Copies all the elements of the collection to the given array beginning at the given index.
Equals(Object) Determines whether the specified object is equal to the current object. (Inherited from Object)
GetEnumerator() Provides an enumerator that iterates through the collection.
GetHashCode() Serves as the default hash function. (Inherited from Object)
GetType() Gets the Type of the current instance. (Inherited from Object)
MemberwiseClone() Creates a shallow copy of the current Object. (Inherited from Object)
ToString() Returns a string that represents the current object. (Inherited from Object)

Extension Methods

Cast<TResult>(IEnumerable) Casts the elements of an IEnumerable to the specified type.
OfType<TResult>(IEnumerable) Filters the elements of an IEnumerable based on a specified type.
AsParallel(IEnumerable) Enables parallelization of a query.
AsQueryable(IEnumerable) Converts an IEnumerable to an IQueryable.

Remarks

  • The GroupCollection class is a zero-based collection class that consists of one or more Group objects that provide information about captured groups in a regular expression match. The collection is immutable (read-only) and has no public constructor. A GroupCollection object is returned by the Match.Groups property.
  • The collection contains one or more System.Text.RegularExpressions.Group objects. If the match is successful, the first element in the collection contains the Group object that corresponds to the entire match. Each subsequent element represents a captured group, if the regular expression includes capturing groups. Matches from numbered (unnamed) capturing groups appear in numeric order before matches from named capturing groups. If the match is unsuccessful, the collection contains a single System.Text.RegularExpressions.Group object whose Success property is false and whose Value property equals String.Empty. For more information, see the "Grouping Constructs and Regular Expression Objects" section in the Grouping Constructs article.
  • To iterate through the members of the collection, you should use the collection iteration construct provided by your language (such as foreach in C# and For Each…Next in Visual Basic) instead of retrieving the enumerator that is returned by the GetEnumerator method. In addition, you can access individual numbered captured groups from the Item[Int32] property (the indexer in C#), and you can access individual named captured groups from the Item[String] property. Note that you can retrieve an array that contains the numbers and names of all capturing groups by calling the Regex.GetGroupNumbers and Regex.GetGroupNames methods, respectively. Both are instance methods and require that you instantiate a Regex object that represents the regular expression to be matched.

Applies to

.NET Framework: 4.8, 4.7.2, 4.7.1, 4.7, 4.6.2, 4.6.1, 4.6, 4.5.2, 4.5.1, 4.5, 4.0, 3.5, 3.0, 2.0, 1.1

See also

  • Group

Examples

Examples of Capture, CaptureCollection, Group, GroupCollection Classes
ASP.NET Code Input:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
       <title>Sample Page</title>
       <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
       <script runat="server">
           Sub Page_Load()
               Dim xstring As String = "01234 67 901 34567 9012 4567890"
               Dim xmatchstr As String = ""
               xmatchstr = xmatchstr & "Given string: """ & xstring & """<br />"
               xmatchstr = xmatchstr & showresult(xstring,"\w+ *")
               xmatchstr = xmatchstr & showresult(xstring,"(\w+ *)")
               xmatchstr = xmatchstr & showresult(xstring,"(\w+ *)+")
               xmatchstr = xmatchstr & showresult(xstring,"((\w+) *)+")
               lbl01.Text = xmatchstr
           End Sub
           Function showresult(xstring,xpattern)
               Dim xmatch As Match
               Dim xcaptures As CaptureCollection
               Dim ycaptures As CaptureCollection
               Dim xgroups As GroupCollection
               Dim xmatchstr As String = ""
               Dim xint As Integer
               Dim yint As Integer
               Dim zint As Integer
               xmatchstr = xmatchstr & "<br />Result of Regex.Match(string,""" & xpattern & """): """
               xmatch = Regex.Match(xstring,xpattern)
               xmatchstr = xmatchstr & xmatch.value & """<br />"
               xcaptures = xmatch.Captures
               xmatchstr = xmatchstr & "->Result of CaptureCollection.Count: """
               xmatchstr = xmatchstr & xcaptures.Count & """<br />"
               For xint = 0 to xcaptures.Count - 1
                   xmatchstr = xmatchstr & "->->Result of CaptureCollection("& xint & ").Value, Index, Length: """
                   xmatchstr = xmatchstr & xcaptures(xint).Value & ", " & xcaptures(xint).Index & ", " & xcaptures(xint).Length & """<br />"
                   xgroups = xmatch.Groups
                   xmatchstr = xmatchstr & "->Result of GroupCollection.Count: """
                   xmatchstr = xmatchstr & xgroups.Count & """<br />"
                   For yint = 0 to xgroups.Count - 1
                       xmatchstr = xmatchstr & "->->Result of GroupCollection("& yint & ").Value, Index, Length: """
                       xmatchstr = xmatchstr & xgroups(yint).Value & ", " & xgroups(yint).Index & ", " & xgroups(yint).Length & """<br />"
                       ycaptures = xgroups(yint).Captures
                       xmatchstr = xmatchstr & "->->->Result of CaptureCollection.Count: """
                       xmatchstr = xmatchstr & ycaptures.Count & """<br />"
                       For zint = 0 to ycaptures.Count - 1
                           xmatchstr = xmatchstr & "->->->->Result of CaptureCollection("& zint & ").Value, Index, Length: """
                           xmatchstr = xmatchstr & ycaptures(zint).Value & ", " & ycaptures(zint).Index & ", " & ycaptures(zint).Length & """<br />"
                       Next
                   Next
               Next
               Return xmatchstr
           End Function
       </script>
    </head>
    <body>
       <% Response.Write ("<h1>This is a Sample Page of Capture, CaptureCollection, Group, GroupCollection Class</h1>") %>
       <p>
           <%-- Set on Page_Load --%>
           <asp:Label id="lbl01" runat="server" />
       </p>
    </body>
</html>
HTML Web Page Embedded Output:

Source/Reference

  • https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions?view=netframework-4.8
  • https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex?view=netframework-4.8
  • https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.capture?view=netframework-4.8
  • https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.capturecollection?view=netframework-4.8#methods
  • https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.group?view=netframework-4.8
  • https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.groupcollection?view=netframework-4.8
  • https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.match?view=netframework-4.8
  • https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.matchcollection?view=netframework-4.8

©sideway

ID: 190700023 Last Updated: 7/23/2019 Revision: 0 Ref:

close

References

  1. Active Server Pages,  , http://msdn.microsoft.com/en-us/library/aa286483.aspx
  2. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx
  3. ASP Best Practices,  , http://technet.microsoft.com/en-us/library/cc939157.aspx
  4. ASP Built-in Objects,  , http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx
  5. Response Object,  , http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx
  6. Request Object,  , http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx
  7. Server Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx
  8. Application Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx
  9. Session Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx
  10. ASPError Object,  , http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx
  11. ObjectContext Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx
  12. Debugging Global.asa Files,  , http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx
  13. How to: Debug Global.asa files,  , http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx
  14. Calling COM Components from ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx
  15. IIS ASP Scripting Reference,  , http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx
  16. ASP Keywords,  , http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx
  17. Creating Simple ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx
  18. Including Files in ASP Applications,  , http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx
  19. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx
  20. FileSystemObject Object,  , http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx
  21. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx,  , ADO Object Model
  22. ADO Fundamentals,  , http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx
close

Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 339

Reference 79

Computer

Hardware 249

Software

Application 213

Digitization 32

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 289

Unicode 504

HTML 66

CSS 65

SVG 46

ASP.NET 270

OS 429

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 34

Coordinate Geometry 2

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019