Regex.Matches 方法

定義

在輸入字串中搜尋所有出現的正規表示式,並傳回所有相符專案。

多載

名稱 Description
Matches(String, String, RegexOptions, TimeSpan)

使用指定的比對選項和超時時間間隔,搜尋指定之正則表示式的所有出現次數。

Matches(String, String, RegexOptions)

使用指定的比對選項,搜尋指定之正則表示式的所有出現次數的指定輸入字串。

Matches(String, Int32)

搜尋指定的輸入字串中所有出現的正則表示式,從字串中指定的起始位置開始。

Matches(String)

搜尋指定的輸入字串中是否有正則表示式的所有出現次數。

Matches(String, String)

搜尋指定的輸入字串,以尋找指定正規表示式的所有專案。

Matches(String, String, RegexOptions, TimeSpan)

來源:
Regex.Match.cs
來源:
Regex.Match.cs
來源:
Regex.Match.cs
來源:
Regex.Match.cs
來源:
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) 方法與 S Match(String, String, RegexOptions, TimeSpan) 類似,不同之處在於回傳輸入字串中所有匹配的資訊,而非單一匹配。

靜態 Matches 方法等同於用指定的正則表達式模式建構一個 Regex 物件,然後呼叫實例方法 Matches

Matches(String, String, RegexOptions, TimeSpan) 方法使用懶惰評估來填充回傳物件 MatchCollection 。 存取此集合的成員,例如CountCopyTo(Array, Int32),會使集合立即被填滿。 為了利用懶得求值,請透過 來 foreach迭代集合。

由於其 raize 評估方式較為懶散,呼叫該 Matches(String, String, RegexOptions, TimeSpan) 方法時不會拋出 RegexMatchTimeoutException 例外。 然而,當對該方法回傳的物件執行 MatchCollection 操作時,若匹配操作超過參數指定的 matchTimeout 逾時區間,則會拋出例外。

給呼叫者的注意事項

我們建議你將參數設定 matchTimeout 為適當的值,例如兩秒。 如果你指定 InfiniteMatchTimeout,則會讓 停止,正則表達式引擎的效能會稍微好一點。 不過,您應該只在下列情況下停用逾時:

  • 正則表達式所處理的輸入衍生自已知且受信任的來源,或包含靜態文字時。 這會排除使用者動態輸入的文字。

  • 當正則表達式模式經過徹底測試,以確保其有效率地處理相符專案、不相符專案和接近相符專案時。

  • 當正則表達式模式不包含任何已知在處理接近相符專案時造成過度回溯的語言元素。

另請參閱

適用於

Matches(String, String, RegexOptions)

來源:
Regex.Match.cs
來源:
Regex.Match.cs
來源:
Regex.Match.cs
來源:
Regex.Match.cs
來源:
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) 方法與 S Match(String, String, RegexOptions) 類似,不同之處在於回傳輸入字串中所有匹配的資訊,而非單一匹配。

靜態 Matches 方法等同於用指定的正則表達式模式建構一個 Regex 物件,然後呼叫實例方法 Matches

Matches(String, String, RegexOptions) 方法使用懶惰評估來填充回傳物件 MatchCollection 。 存取此集合的成員,例如CountCopyTo(Array, Int32),會使集合立即被填滿。 為了利用懶得求值,請透過 來 foreach迭代集合。

由於其 raize 評估方式較為懶散,呼叫該 Matches(String, String, RegexOptions) 方法時不會拋出 RegexMatchTimeoutException 例外。 然而,當對該方法回傳的物件執行 MatchCollection 操作,且匹配操作超過逾時區間時,例外會被拋出。

給呼叫者的注意事項

這個方法會在間隔後逾時,這個間隔等於呼叫它之應用程式域的預設逾時值。 若應用程式域尚未定義逾時值,則使用阻止方法逾時的值 InfiniteMatchTimeout。 建議的靜態方法為 Matches(String, String, RegexOptions, TimeSpan),用於取得多個模式匹配,並可設定逾時間隔。

另請參閱

適用於

Matches(String, Int32)

來源:
Regex.Match.cs
來源:
Regex.Match.cs
來源:
Regex.Match.cs
來源:
Regex.Match.cs
來源:
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) 方法與 S Match(String, Int32) 類似,不同之處在於回傳輸入字串中所有匹配的資訊,而非單一匹配。

欲了解更多細節 startat,請參閱備註 Match(String, Int32)

Matches(String, Int32) 方法使用懶惰評估來填充回傳物件 MatchCollection 。 存取此集合的成員,例如CountCopyTo(Array, Int32),會使集合立即被填滿。 為了利用懶得求值,請透過 來 foreach迭代集合。

由於其 raize 評估方式較為懶散,呼叫該 Matches(String, Int32) 方法時不會拋出 RegexMatchTimeoutException 例外。 然而,當該方法回傳的物件執行 MatchCollection 操作時,若 MatchTimeout 該屬性未 InfiniteMatchTimeout 達標且匹配操作超過逾時區間,則會拋出例外。

另請參閱

適用於

Matches(String)

來源:
Regex.Match.cs
來源:
Regex.Match.cs
來源:
Regex.Match.cs
來源:
Regex.Match.cs
來源:
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) 方法與 S Match(String) 類似,不同之處在於回傳輸入字串中所有匹配的資訊,而非單一匹配。 該集合僅包含配對,並於第一個非配對時終止。

Matches(String) 方法使用懶惰評估來填充回傳物件 MatchCollection 。 存取此集合的成員,例如CountCopyTo(Array, Int32),會使集合立即被填滿。 為了利用懶得求值,請透過 來 foreach迭代集合。

由於其 raize 評估方式較為懶散,呼叫該 Matches(String) 方法時不會拋出 RegexMatchTimeoutException 例外。 然而,當該方法回傳的物件執行 MatchCollection 操作時,若 MatchTimeout 該屬性未 InfiniteMatchTimeout 達標且匹配操作超過逾時區間,則會拋出例外。

另請參閱

適用於

Matches(String, String)

來源:
Regex.Match.cs
來源:
Regex.Match.cs
來源:
Regex.Match.cs
來源:
Regex.Match.cs
來源:
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) 方法與 S Match(String, String) 類似,不同之處在於回傳輸入字串中所有匹配的資訊,而非單一匹配。

靜態 Matches 方法等同於用指定的正則表達式模式建構一個 Regex 物件,然後呼叫實例方法 Matches

Matches(String, String) 方法使用懶惰評估來填充回傳物件 MatchCollection 。 存取此集合的成員,例如CountCopyTo(Array, Int32),會使集合立即被填滿。 為了利用懶得求值,請透過 來 foreach迭代集合。

由於其 raize 評估方式較為懶散,呼叫該 Matches(String, String) 方法時不會拋出 RegexMatchTimeoutException 例外。 然而,當對該方法回傳的物件執行 MatchCollection 操作,且匹配操作超過逾時區間時,例外會被拋出。

給呼叫者的注意事項

這個方法會在間隔後逾時,這個間隔等於呼叫它之應用程式域的預設逾時值。 若應用程式域尚未定義逾時值,則使用阻止方法逾時的值 InfiniteMatchTimeout。 建議的靜態方法為 Matches(String, String, RegexOptions, TimeSpan),用於取得多個模式匹配,該方法允許您指定逾時間隔。

另請參閱

適用於