Regex.Matches 方法

定义

在输入字符串中搜索正则表达式的所有匹配项,并返回所有匹配项。

重载

名称 说明
Matches(String, String, RegexOptions, TimeSpan)

使用指定的匹配选项和超时间隔搜索指定正则表达式的所有匹配项的指定输入字符串。

Matches(String, String, RegexOptions)

使用指定的匹配选项搜索指定正则表达式的所有匹配项的指定输入字符串。

Matches(String, Int32)

在指定的输入字符串中搜索正则表达式的所有匹配项,从字符串中的指定起始位置开始。

Matches(String)

在指定的输入字符串中搜索正则表达式的所有匹配项。

Matches(String, String)

在指定的输入字符串中搜索指定正则表达式的所有匹配项。

Matches(String, String, RegexOptions, TimeSpan)

Source:
Regex.Match.cs
Source:
Regex.Match.cs
Source:
Regex.Match.cs
Source:
Regex.Match.cs
Source:
Regex.Match.cs

使用指定的匹配选项和超时间隔搜索指定正则表达式的所有匹配项的指定输入字符串。

public:
 static System::Text::RegularExpressions::MatchCollection ^ Matches(System::String ^ input, System::String ^ pattern, System::Text::RegularExpressions::RegexOptions options, TimeSpan matchTimeout);
public static System.Text.RegularExpressions.MatchCollection Matches(string input, string pattern, System.Text.RegularExpressions.RegexOptions options, TimeSpan matchTimeout);
static member Matches : string * string * System.Text.RegularExpressions.RegexOptions * TimeSpan -> System.Text.RegularExpressions.MatchCollection
Public Shared Function Matches (input As String, pattern As String, options As RegexOptions, matchTimeout As TimeSpan) As MatchCollection

参数

input
String

要搜索匹配项的字符串。

pattern
String

要匹配的正则表达式模式。

options
RegexOptions

枚举值的按位组合,指定用于匹配的选项。

matchTimeout
TimeSpan

超时间隔,或 InfiniteMatchTimeout 指示方法不应超时。

返回

搜索找到的对象集合 Match 。 如果未找到匹配项,该方法将返回空集合对象。

例外

发生正则表达式分析错误。

inputpatternnull.

options 不是值的有效按位组合 RegexOptions 。 - 或 - matchTimeout 为负、零或大于大约 24 天。

注解

该方法 Matches(String, String, RegexOptions, TimeSpan)Match(String, String, RegexOptions, TimeSpan) 该方法类似,只不过它返回有关输入字符串中找到的所有匹配项的信息,而不是单个匹配项。

静态Matches方法等效于使用指定的正则表达式模式和调用实例方法Regex构造Matches对象。

该方法 Matches(String, String, RegexOptions, TimeSpan) 使用延迟计算来填充返回 MatchCollection 的对象。 访问此集合的成员,例如 Count ,并 CopyTo(Array, Int32) 导致集合立即填充。 若要利用延迟计算,请使用 foreach循环访问集合。

由于延迟计算,调用 Matches(String, String, RegexOptions, TimeSpan) 该方法不会引发 RegexMatchTimeoutException 异常。 但是,如果匹配操作超过参数指定的matchTimeout超时间隔,则当对此方法返回的对象执行MatchCollection操作时,将引发异常。

调用方说明

建议将 matchTimeout 参数设置为适当的值,例如两秒。 如果通过指定 InfiniteMatchTimeout禁用超时,则正则表达式引擎的性能略有提高。 但是,应仅在以下情况下禁用超时:

  • 当正则表达式处理的输入派生自已知且受信任的源或包含静态文本时。 这不包括用户动态输入的文本。

  • 当正则表达式模式经过全面测试以确保它有效地处理匹配项、非匹配项和接近匹配项时。

  • 当正则表达式模式不包含任何已知在处理接近匹配时导致过度回溯的语言元素。

另请参阅

适用于

Matches(String, String, RegexOptions)

Source:
Regex.Match.cs
Source:
Regex.Match.cs
Source:
Regex.Match.cs
Source:
Regex.Match.cs
Source:
Regex.Match.cs

使用指定的匹配选项搜索指定正则表达式的所有匹配项的指定输入字符串。

public:
 static System::Text::RegularExpressions::MatchCollection ^ Matches(System::String ^ input, System::String ^ pattern, System::Text::RegularExpressions::RegexOptions options);
public static System.Text.RegularExpressions.MatchCollection Matches(string input, string pattern, System.Text.RegularExpressions.RegexOptions options);
static member Matches : string * string * System.Text.RegularExpressions.RegexOptions -> System.Text.RegularExpressions.MatchCollection
Public Shared Function Matches (input As String, pattern As String, options As RegexOptions) As MatchCollection

参数

input
String

要搜索匹配项的字符串。

pattern
String

要匹配的正则表达式模式。

options
RegexOptions

枚举值的按位组合,指定用于匹配的选项。

返回

搜索找到的对象集合 Match 。 如果未找到匹配项,该方法将返回空集合对象。

例外

发生正则表达式分析错误。

inputpatternnull.

options 不是值的有效按位组合 RegexOptions

注解

该方法 Matches(String, String, RegexOptions)Match(String, String, RegexOptions) 该方法类似,只不过它返回有关输入字符串中找到的所有匹配项的信息,而不是单个匹配项。

静态Matches方法等效于使用指定的正则表达式模式和调用实例方法Regex构造Matches对象。

该方法 Matches(String, String, RegexOptions) 使用延迟计算来填充返回 MatchCollection 的对象。 访问此集合的成员,例如 Count ,并 CopyTo(Array, Int32) 导致集合立即填充。 若要利用延迟计算,请使用 foreach循环访问集合。

由于延迟计算,调用 Matches(String, String, RegexOptions) 该方法不会引发 RegexMatchTimeoutException 异常。 但是,如果匹配操作超过超时间隔,则会在此方法返回的对象上 MatchCollection 执行操作时引发异常。

调用方说明

此方法在一个时间间隔后超时,该值等于调用它的应用程序域的默认超时值。 如果未为应用程序域定义超时值,则使用阻止方法超时的值 InfiniteMatchTimeout。 用于检索多个模式匹配项的建议静态方法是 Matches(String, String, RegexOptions, TimeSpan),这允许设置超时间隔。

另请参阅

适用于

Matches(String, Int32)

Source:
Regex.Match.cs
Source:
Regex.Match.cs
Source:
Regex.Match.cs
Source:
Regex.Match.cs
Source:
Regex.Match.cs

在指定的输入字符串中搜索正则表达式的所有匹配项,从字符串中的指定起始位置开始。

public:
 System::Text::RegularExpressions::MatchCollection ^ Matches(System::String ^ input, int startat);
public System.Text.RegularExpressions.MatchCollection Matches(string input, int startat);
member this.Matches : string * int -> System.Text.RegularExpressions.MatchCollection
Public Function Matches (input As String, startat As Integer) As MatchCollection

参数

input
String

要搜索匹配项的字符串。

startat
Int32

要从其开始搜索的输入字符串中的字符位置。

返回

搜索找到的对象集合 Match 。 如果未找到匹配项,该方法将返回空集合对象。

例外

inputnull

startat 小于零或大于长度 input

注解

该方法 Matches(String, Int32)Match(String, Int32) 该方法类似,只不过它返回有关输入字符串中找到的所有匹配项的信息,而不是单个匹配项。

有关更多详细信息 startat,请参阅其备注 Match(String, Int32)

该方法 Matches(String, Int32) 使用延迟计算来填充返回 MatchCollection 的对象。 访问此集合的成员,例如 Count ,并 CopyTo(Array, Int32) 导致集合立即填充。 若要利用延迟计算,请使用 foreach循环访问集合。

由于延迟计算,调用 Matches(String, Int32) 该方法不会引发 RegexMatchTimeoutException 异常。 但是,如果在此方法返回的对象上MatchCollection执行操作,并且MatchTimeoutInfiniteMatchTimeout匹配的操作超过超时间隔,则会引发异常。

另请参阅

适用于

Matches(String)

Source:
Regex.Match.cs
Source:
Regex.Match.cs
Source:
Regex.Match.cs
Source:
Regex.Match.cs
Source:
Regex.Match.cs

在指定的输入字符串中搜索正则表达式的所有匹配项。

public:
 System::Text::RegularExpressions::MatchCollection ^ Matches(System::String ^ input);
public System.Text.RegularExpressions.MatchCollection Matches(string input);
member this.Matches : string -> System.Text.RegularExpressions.MatchCollection
Public Function Matches (input As String) As MatchCollection

参数

input
String

要搜索匹配项的字符串。

返回

搜索找到的对象集合 Match 。 如果未找到匹配项,该方法将返回空集合对象。

例外

inputnull

注解

该方法 Matches(String)Match(String) 该方法类似,只不过它返回有关输入字符串中找到的所有匹配项的信息,而不是单个匹配项。 该集合仅包含匹配项,并在第一个不匹配时终止。

该方法 Matches(String) 使用延迟计算来填充返回 MatchCollection 的对象。 访问此集合的成员,例如 Count ,并 CopyTo(Array, Int32) 导致集合立即填充。 若要利用延迟计算,请使用 foreach循环访问集合。

由于延迟计算,调用 Matches(String) 该方法不会引发 RegexMatchTimeoutException 异常。 但是,如果在此方法返回的对象上MatchCollection执行操作,并且MatchTimeoutInfiniteMatchTimeout匹配的操作超过超时间隔,则会引发异常。

另请参阅

适用于

Matches(String, String)

Source:
Regex.Match.cs
Source:
Regex.Match.cs
Source:
Regex.Match.cs
Source:
Regex.Match.cs
Source:
Regex.Match.cs

在指定的输入字符串中搜索指定正则表达式的所有匹配项。

public:
 static System::Text::RegularExpressions::MatchCollection ^ Matches(System::String ^ input, System::String ^ pattern);
public static System.Text.RegularExpressions.MatchCollection Matches(string input, string pattern);
static member Matches : string * string -> System.Text.RegularExpressions.MatchCollection
Public Shared Function Matches (input As String, pattern As String) As MatchCollection

参数

input
String

要搜索匹配项的字符串。

pattern
String

要匹配的正则表达式模式。

返回

搜索找到的对象集合 Match 。 如果未找到匹配项,该方法将返回空集合对象。

例外

发生正则表达式分析错误。

inputpatternnull.

注解

该方法 Matches(String, String)Match(String, String) 该方法类似,只不过它返回有关输入字符串中找到的所有匹配项的信息,而不是单个匹配项。

静态Matches方法等效于使用指定的正则表达式模式和调用实例方法Regex构造Matches对象。

该方法 Matches(String, String) 使用延迟计算来填充返回 MatchCollection 的对象。 访问此集合的成员,例如 Count ,并 CopyTo(Array, Int32) 导致集合立即填充。 若要利用延迟计算,请使用 foreach循环访问集合。

由于延迟计算,调用 Matches(String, String) 该方法不会引发 RegexMatchTimeoutException 异常。 但是,如果匹配操作超过超时间隔,则会在此方法返回的对象上 MatchCollection 执行操作时引发异常。

调用方说明

此方法在一个时间间隔后超时,该值等于调用它的应用程序域的默认超时值。 如果未为应用程序域定义超时值,则使用阻止方法超时的值 InfiniteMatchTimeout。 用于检索多个模式匹配项的建议静态方法是 Matches(String, String, RegexOptions, TimeSpan),它允许你指定超时间隔。

另请参阅

适用于