CaptureCollection 클래스
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
단일 캡처 그룹이 만든 캡처 집합을 나타냅니다. 컬렉션은 변경할 수 없으며(읽기 전용) 공용 생성자가 없습니다.
public ref class CaptureCollection : System::Collections::ICollection
public ref class CaptureCollection : System::Collections::Generic::ICollection<System::Text::RegularExpressions::Capture ^>, System::Collections::Generic::IEnumerable<System::Text::RegularExpressions::Capture ^>, System::Collections::Generic::IList<System::Text::RegularExpressions::Capture ^>, System::Collections::Generic::IReadOnlyCollection<System::Text::RegularExpressions::Capture ^>, System::Collections::Generic::IReadOnlyList<System::Text::RegularExpressions::Capture ^>, System::Collections::IList
public class CaptureCollection : System.Collections.ICollection
public class CaptureCollection : System.Collections.Generic.ICollection<System.Text.RegularExpressions.Capture>, System.Collections.Generic.IEnumerable<System.Text.RegularExpressions.Capture>, System.Collections.Generic.IList<System.Text.RegularExpressions.Capture>, System.Collections.Generic.IReadOnlyCollection<System.Text.RegularExpressions.Capture>, System.Collections.Generic.IReadOnlyList<System.Text.RegularExpressions.Capture>, System.Collections.IList
[System.Serializable]
public class CaptureCollection : System.Collections.ICollection
type CaptureCollection = class
interface ICollection
interface IEnumerable
type CaptureCollection = class
interface ICollection<Capture>
interface seq<Capture>
interface IEnumerable
interface IList<Capture>
interface IReadOnlyCollection<Capture>
interface IReadOnlyList<Capture>
interface ICollection
interface IList
type CaptureCollection = class
interface ICollection
interface IEnumerable
interface ICollection<Capture>
interface seq<Capture>
interface IList<Capture>
interface IReadOnlyCollection<Capture>
interface IReadOnlyList<Capture>
interface IList
[<System.Serializable>]
type CaptureCollection = class
interface ICollection
interface IEnumerable
Public Class CaptureCollection
Implements ICollection
Public Class CaptureCollection
Implements ICollection(Of Capture), IEnumerable(Of Capture), IList, IList(Of Capture), IReadOnlyCollection(Of Capture), IReadOnlyList(Of Capture)
- 상속
-
CaptureCollection
- 특성
- 구현
다음 예제에서는 Group.Captures 반환된 CaptureCollection 개체의 Capture 개체와 Match.Captures
속성을 비교합니다. 또한 Group 개체를 Group.Captures 속성에서 반환된 CaptureCollectionCapture 개체와 비교합니다. 이 예제에서는 다음 두 정규식을 사용하여 단일 입력 문자열에서 일치 항목을 찾습니다.
\b\w+\W{1,2}
이 정규식 패턴은 하나 이상의 단어 문자로 구성된 단어와 공백 또는 문장 부호와 같은 단어가 아닌 문자를 하나 또는 두 개씩 식별합니다. 정규식에는 캡처링 그룹이 포함되지 않습니다. 이 예제의 출력은 Match 개체와 Group.Captures 반환된 CaptureCollection 개체와
Match.Captures
속성 모두 동일한 일치 항목에 대한 정보를 포함하고 있음을 보여줍니다.(\b\w+\W{1,2})+
이 정규식 패턴은 문장의 단어를 식별합니다. 이 패턴은 하나 이상의 단어 문자와 한두 개의 단어가 아닌 문자로 구성된 단일 캡처 그룹을 정의합니다. 정규식 패턴은
+
수량자를 사용하여 이 그룹의 하나 이상의 발생과 일치합니다. 이 예제의 출력은 Match 개체와Match.Captures
속성에서 반환된 CaptureCollection 개체에 동일한 일치 항목에 대한 정보가 포함되어 있음을 보여줍니다. 정규식에서 유일한 캡처링 그룹에 해당하는 두 번째 Group 개체는 마지막으로 캡처한 문자열만 식별하는 반면, 첫 번째 캡처링 그룹의 Group.Captures 속성에서 반환된 CaptureCollection 개체에는 캡처된 모든 부분 문자열이 포함됩니다.
using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern;
string input = "The young, hairy, and tall dog slowly walked across the yard.";
Match match;
// Match a word with a pattern that has no capturing groups.
pattern = @"\b\w+\W{1,2}";
match = Regex.Match(input, pattern);
Console.WriteLine("Pattern: " + pattern);
Console.WriteLine("Match: " + match.Value);
Console.WriteLine(" Match.Captures: {0}", match.Captures.Count);
for (int ctr = 0; ctr < match.Captures.Count; ctr++)
Console.WriteLine(" {0}: '{1}'", ctr, match.Captures[ctr].Value);
Console.WriteLine(" Match.Groups: {0}", match.Groups.Count);
for (int groupCtr = 0; groupCtr < match.Groups.Count; groupCtr++)
{
Console.WriteLine(" Group {0}: '{1}'",
groupCtr, match.Groups[groupCtr].Value);
Console.WriteLine(" Group({0}).Captures: {1}",
groupCtr, match.Groups[groupCtr].Captures.Count);
for (int captureCtr = 0; captureCtr < match.Groups[groupCtr].Captures.Count; captureCtr++)
Console.WriteLine(" Capture {0}: '{1}'",
captureCtr,
match.Groups[groupCtr].Captures[captureCtr].Value);
}
Console.WriteLine("-----\n");
// Match a sentence with a pattern that has a quantifier that
// applies to the entire group.
pattern = @"(\b\w+\W{1,2})+";
match = Regex.Match(input, pattern);
Console.WriteLine("Pattern: " + pattern);
Console.WriteLine("Match: " + match.Value);
Console.WriteLine(" Match.Captures: {0}", match.Captures.Count);
for (int ctr = 0; ctr < match.Captures.Count; ctr++)
Console.WriteLine(" {0}: '{1}'", ctr, match.Captures[ctr].Value);
Console.WriteLine(" Match.Groups: {0}", match.Groups.Count);
for (int groupCtr = 0; groupCtr < match.Groups.Count; groupCtr++)
{
Console.WriteLine(" Group {0}: '{1}'", groupCtr, match.Groups[groupCtr].Value);
Console.WriteLine(" Group({0}).Captures: {1}",
groupCtr, match.Groups[groupCtr].Captures.Count);
for (int captureCtr = 0; captureCtr < match.Groups[groupCtr].Captures.Count; captureCtr++)
Console.WriteLine(" Capture {0}: '{1}'", captureCtr, match.Groups[groupCtr].Captures[captureCtr].Value);
}
}
}
// The example displays the following output:
// Pattern: \b\w+\W{1,2}
// Match: The
// Match.Captures: 1
// 0: 'The '
// Match.Groups: 1
// Group 0: 'The '
// Group(0).Captures: 1
// Capture 0: 'The '
// -----
//
// Pattern: (\b\w+\W{1,2})+
// Match: The young, hairy, and tall dog slowly walked across the yard.
// Match.Captures: 1
// 0: 'The young, hairy, and tall dog slowly walked across the yard.'
// Match.Groups: 2
// Group 0: 'The young, hairy, and tall dog slowly walked across the yard.'
// Group(0).Captures: 1
// Capture 0: 'The young, hairy, and tall dog slowly walked across the yard.'
// Group 1: 'yard.'
// Group(1).Captures: 11
// Capture 0: 'The '
// Capture 1: 'young, '
// Capture 2: 'hairy, '
// Capture 3: 'and '
// Capture 4: 'tall '
// Capture 5: 'dog '
// Capture 6: 'slowly '
// Capture 7: 'walked '
// Capture 8: 'across '
// Capture 9: 'the '
// Capture 10: 'yard.'
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim pattern As String
Dim input As String = "The young, hairy, and tall dog slowly walked across the yard."
Dim match As Match
' Match a word with a pattern that has no capturing groups.
pattern = "\b\w+\W{1,2}"
match = Regex.Match(input, pattern)
Console.WriteLine("Pattern: " + pattern)
Console.WriteLine("Match: " + match.Value)
Console.WriteLine(" Match.Captures: {0}", match.Captures.Count)
For ctr As Integer = 0 To match.Captures.Count - 1
Console.WriteLine(" {0}: '{1}'", ctr, match.Captures(ctr).Value)
Next
Console.WriteLine(" Match.Groups: {0}", match.Groups.Count)
For groupCtr As Integer = 0 To match.Groups.Count - 1
Console.WriteLine(" Group {0}: '{1}'", groupCtr, match.Groups(groupCtr).Value)
Console.WriteLine(" Group({0}).Captures: {1}", _
groupCtr, match.Groups(groupCtr).Captures.Count)
For captureCtr As Integer = 0 To match.Groups(groupCtr).Captures.Count - 1
Console.WriteLine(" Capture {0}: '{1}'", _
captureCtr, _
match.Groups(groupCtr).Captures(captureCtr).Value)
Next
Next
Console.WriteLine("-----")
Console.WriteLine()
' Match a sentence with a pattern that has a quantifier that
' applies to the entire group.
pattern = "(\b\w+\W{1,2})+"
match = Regex.Match(input, pattern)
Console.WriteLine("Pattern: " + pattern)
Console.WriteLine("Match: " + match.Value)
Console.WriteLine(" Match.Captures: {0}", match.Captures.Count)
For ctr As Integer = 0 To match.Captures.Count - 1
Console.WriteLine(" {0}: '{1}'", ctr, match.Captures(ctr).Value)
Next
Console.WriteLine(" Match.Groups: {0}", match.Groups.Count)
For groupCtr As Integer = 0 To match.Groups.Count - 1
Console.WriteLine(" Group {0}: '{1}'", groupCtr, match.Groups(groupCtr).Value)
Console.WriteLine(" Group({0}).Captures: {1}", _
groupCtr, match.Groups(groupCtr).Captures.Count)
For captureCtr As Integer = 0 To match.Groups(groupCtr).Captures.Count - 1
Console.WriteLine(" Capture {0}: '{1}'", captureCtr, match.Groups(groupCtr).Captures(captureCtr).Value)
Next
Next
End Sub
End Module
' The example displays the following output:
' Pattern: \b\w+\W{1,2}
' Match: The
' Match.Captures: 1
' 0: 'The '
' Match.Groups: 1
' Group 0: 'The '
' Group(0).Captures: 1
' Capture 0: 'The '
' -----
'
' Pattern: (\b\w+\W{1,2})+
' Match: The young, hairy, and tall dog slowly walked across the yard.
' Match.Captures: 1
' 0: 'The young, hairy, and tall dog slowly walked across the yard.'
' Match.Groups: 2
' Group 0: 'The young, hairy, and tall dog slowly walked across the yard.'
' Group(0).Captures: 1
' Capture 0: 'The young, hairy, and tall dog slowly walked across the yard.'
' Group 1: 'yard.'
' Group(1).Captures: 11
' Capture 0: 'The '
' Capture 1: 'young, '
' Capture 2: 'hairy, '
' Capture 3: 'and '
' Capture 4: 'tall '
' Capture 5: 'dog '
' Capture 6: 'slowly '
' Capture 7: 'walked '
' Capture 8: 'across '
' Capture 9: 'the '
' Capture 10: 'yard.'
컬렉션은 변경할 수 없으며(읽기 전용) 공용 생성자가 없습니다. CaptureCollection 개체에는 하나 이상의 Capture 개체가 포함되어 있습니다.
CaptureCollection 클래스의 인스턴스는 다음 속성에 의해 반환됩니다.
Group.Captures 속성입니다. 컬렉션의 각 멤버는 캡처링 그룹에서 캡처한 부분 문자열을 나타냅니다. 수량자가 캡처링 그룹에 적용되지 않은 경우 CaptureCollectionGroup 개체와 동일한 캡처된 부분 문자열을 나타내는 단일 Capture 개체를 포함합니다. 수량자가 캡처링 그룹에 적용되는 경우 CaptureCollection 캡처된 각 부분 문자열에 대해 하나의 Capture 개체를 포함하고 Group 개체는 마지막으로 캡처한 부분 문자열에 대한 정보만 제공합니다.
Match.Captures
속성입니다. 이 경우 컬렉션은 전체적으로 일치 항목에 대한 정보를 제공하는 단일 Capture 개체로 구성됩니다. 즉, CaptureCollection 개체는 Match 개체와 동일한 정보를 제공합니다.
컬렉션의 멤버를 반복하려면 GetEnumerator 메서드에서 반환되는 열거자를 검색하는 대신 언어에서 제공하는 컬렉션 반복 구문(예: C#의 foreach
및 Visual Basic에서는Next
For Each
)을 사용해야 합니다.
Count |
그룹에서 캡처한 부분 문자열 수를 가져옵니다. |
Is |
컬렉션이 읽기 전용인지 여부를 나타내는 값을 가져옵니다. |
Is |
컬렉션에 대한 액세스가 동기화되는지 여부를 나타내는 값을 가져옵니다(스레드로부터 안전). |
Item[Int32] |
컬렉션의 개별 멤버를 가져옵니다. |
Sync |
컬렉션에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다. |
Copy |
컬렉션의 모든 요소를 지정된 인덱스에서 시작하는 지정된 배열에 복사합니다. |
Copy |
|
Equals(Object) |
지정된 개체가 현재 개체와 같은지 여부를 확인합니다. (다음에서 상속됨 Object) |
Get |
컬렉션을 반복하는 열거자를 제공합니다. |
Get |
기본 해시 함수로 사용됩니다. (다음에서 상속됨 Object) |
Get |
현재 인스턴스의 Type 가져옵니다. (다음에서 상속됨 Object) |
Memberwise |
현재 Object단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
To |
현재 개체를 나타내는 문자열을 반환합니다. (다음에서 상속됨 Object) |
제품 | 버전 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET 피드백
.NET은(는) 오픈 소스 프로젝트입니다. 다음 링크를 선택하여 피드백을 제공해 주세요.