Regex.Count Method

Definition

Overloads

Count(ReadOnlySpan<Char>)

Searches an input span for all occurrences of a regular expression and returns the number of matches.

Count(String)

Searches an input string for all occurrences of a regular expression and returns the number of matches.

Count(ReadOnlySpan<Char>, Int32)

Searches an input span for all occurrences of a regular expression and returns the number of matches.

Count(ReadOnlySpan<Char>, String)

Searches an input span for all occurrences of a regular expression and returns the number of matches.

Count(String, String)

Searches an input string for all occurrences of a regular expression and returns the number of matches.

Count(ReadOnlySpan<Char>, String, RegexOptions)

Searches an input span for all occurrences of a regular expression and returns the number of matches.

Count(String, String, RegexOptions)

Searches an input string for all occurrences of a regular expression and returns the number of matches.

Count(ReadOnlySpan<Char>, String, RegexOptions, TimeSpan)

Searches an input span for all occurrences of a regular expression and returns the number of matches.

Count(String, String, RegexOptions, TimeSpan)

Searches an input string for all occurrences of a regular expression and returns the number of matches.

Count(ReadOnlySpan<Char>)

Source:
Regex.Count.cs
Source:
Regex.Count.cs
Source:
Regex.Count.cs

Searches an input span for all occurrences of a regular expression and returns the number of matches.

C#
public int Count(ReadOnlySpan<char> input);

Parameters

input
ReadOnlySpan<Char>

The span to search for a match.

Returns

The number of matches.

Applies to

.NET 10 and other versions
Product Versions
.NET 7, 8, 9, 10

Count(String)

Source:
Regex.Count.cs
Source:
Regex.Count.cs
Source:
Regex.Count.cs

Searches an input string for all occurrences of a regular expression and returns the number of matches.

C#
public int Count(string input);

Parameters

input
String

The string to search for a match.

Returns

The number of matches.

Exceptions

input is null.

Applies to

.NET 10 and other versions
Product Versions
.NET 7, 8, 9, 10

Count(ReadOnlySpan<Char>, Int32)

Source:
Regex.Count.cs
Source:
Regex.Count.cs
Source:
Regex.Count.cs

Searches an input span for all occurrences of a regular expression and returns the number of matches.

C#
public int Count(ReadOnlySpan<char> input, int startat);

Parameters

input
ReadOnlySpan<Char>

The span to search for a match.

startat
Int32

The zero-based character position at which to start the search.

Returns

The number of matches.

Applies to

.NET 10 and other versions
Product Versions
.NET 7, 8, 9, 10

Count(ReadOnlySpan<Char>, String)

Source:
Regex.Count.cs
Source:
Regex.Count.cs
Source:
Regex.Count.cs

Searches an input span for all occurrences of a regular expression and returns the number of matches.

C#
public static int Count(ReadOnlySpan<char> input, string pattern);

Parameters

input
ReadOnlySpan<Char>

The span to search for a match.

pattern
String

The regular expression pattern to match.

Returns

The number of matches.

Exceptions

A regular expression parsing error occurred.

Applies to

.NET 10 and other versions
Product Versions
.NET 7, 8, 9, 10

Count(String, String)

Source:
Regex.Count.cs
Source:
Regex.Count.cs
Source:
Regex.Count.cs

Searches an input string for all occurrences of a regular expression and returns the number of matches.

C#
public static int Count(string input, string pattern);

Parameters

input
String

The string to search for a match.

pattern
String

The regular expression pattern to match.

Returns

The number of matches.

Exceptions

input or pattern is null.

A regular expression parsing error occurred.

Applies to

.NET 10 and other versions
Product Versions
.NET 7, 8, 9, 10

Count(ReadOnlySpan<Char>, String, RegexOptions)

Source:
Regex.Count.cs
Source:
Regex.Count.cs
Source:
Regex.Count.cs

Searches an input span for all occurrences of a regular expression and returns the number of matches.

C#
public static int Count(ReadOnlySpan<char> input, string pattern, System.Text.RegularExpressions.RegexOptions options);

Parameters

input
ReadOnlySpan<Char>

The span to search for a match.

pattern
String

The regular expression pattern to match.

options
RegexOptions

A bitwise combination of the enumeration values that specify options for matching.

Returns

The number of matches.

Exceptions

options is not a valid bitwise combination of RegexOptions values.

A regular expression parsing error occurred.

Applies to

.NET 10 and other versions
Product Versions
.NET 7, 8, 9, 10

Count(String, String, RegexOptions)

Source:
Regex.Count.cs
Source:
Regex.Count.cs
Source:
Regex.Count.cs

Searches an input string for all occurrences of a regular expression and returns the number of matches.

C#
public static int Count(string input, string pattern, System.Text.RegularExpressions.RegexOptions options);

Parameters

input
String

The string to search for a match.

pattern
String

The regular expression pattern to match.

options
RegexOptions

A bitwise combination of the enumeration values that specify options for matching.

Returns

The number of matches.

Exceptions

input or pattern is null.

options is not a valid bitwise combination of RegexOptions values.

A regular expression parsing error occurred.

Applies to

.NET 10 and other versions
Product Versions
.NET 7, 8, 9, 10

Count(ReadOnlySpan<Char>, String, RegexOptions, TimeSpan)

Source:
Regex.Count.cs
Source:
Regex.Count.cs
Source:
Regex.Count.cs

Searches an input span for all occurrences of a regular expression and returns the number of matches.

C#
public static int Count(ReadOnlySpan<char> input, string pattern, System.Text.RegularExpressions.RegexOptions options, TimeSpan matchTimeout);

Parameters

input
ReadOnlySpan<Char>

The span to search for a match.

pattern
String

The regular expression pattern to match.

options
RegexOptions

A bitwise combination of the enumeration values that specify options for matching.

matchTimeout
TimeSpan

A time-out interval, or InfiniteMatchTimeout to indicate that the method should not time out.

Returns

The number of matches.

Exceptions

options is not a valid bitwise combination of RegexOptions values, or matchTimeout is negative, zero, or greater than approximately 24 days.

A regular expression parsing error occurred.

Applies to

.NET 10 and other versions
Product Versions
.NET 7, 8, 9, 10

Count(String, String, RegexOptions, TimeSpan)

Source:
Regex.Count.cs
Source:
Regex.Count.cs
Source:
Regex.Count.cs

Searches an input string for all occurrences of a regular expression and returns the number of matches.

C#
public static int Count(string input, string pattern, System.Text.RegularExpressions.RegexOptions options, TimeSpan matchTimeout);

Parameters

input
String

The string to search for a match.

pattern
String

The regular expression pattern to match.

options
RegexOptions

A bitwise combination of the enumeration values that specify options for matching.

matchTimeout
TimeSpan

A time-out interval, or InfiniteMatchTimeout to indicate that the method should not time out.

Returns

The number of matches.

Exceptions

input or pattern is null.

options is not a valid bitwise combination of RegexOptions values, or matchTimeout is negative, zero, or greater than approximately 24 days.

A regular expression parsing error occurred.

Applies to

.NET 10 and other versions
Product Versions
.NET 7, 8, 9, 10