vb.net Regex.IsMatch方法 九种重载的方法编程实例
时间: 2024-01-21 11:17:16 浏览: 37
以下是九种重载的实例:
1. 检查字符串是否与正则表达式匹配,返回布尔值。
```
Dim str As String = "Hello World"
Dim pattern As String = "Hello"
Dim isMatch As Boolean = Regex.IsMatch(str, pattern)
Console.WriteLine(isMatch)
```
2. 检查字符串是否与正则表达式匹配,返回布尔值,并设置匹配选项。
```
Dim str As String = "HELLO WORLD"
Dim pattern As String = "hello"
Dim options As RegexOptions = RegexOptions.IgnoreCase
Dim isMatch As Boolean = Regex.IsMatch(str, pattern, options)
Console.WriteLine(isMatch)
```
3. 检查字符串的某个子串是否与正则表达式匹配,返回布尔值。
```
Dim str As String = "This is a test"
Dim pattern As String = "test"
Dim startIndex As Integer = 10
Dim isMatch As Boolean = Regex.IsMatch(str, pattern, startIndex)
Console.WriteLine(isMatch)
```
4. 检查字符串的某个子串是否与正则表达式匹配,返回布尔值,并设置匹配选项。
```
Dim str As String = "This Is A Test"
Dim pattern As String = "test"
Dim startIndex As Integer = 10
Dim options As RegexOptions = RegexOptions.IgnoreCase
Dim isMatch As Boolean = Regex.IsMatch(str, pattern, options, startIndex)
Console.WriteLine(isMatch)
```
5. 检查字符串的某个子串是否与正则表达式匹配,返回布尔值,并设置匹配选项和超时时间。
```
Dim str As String = "This Is A Test"
Dim pattern As String = "test"
Dim startIndex As Integer = 10
Dim options As RegexOptions = RegexOptions.IgnoreCase
Dim timeout As TimeSpan = TimeSpan.FromSeconds(1)
Dim isMatch As Boolean = Regex.IsMatch(str, pattern, options, timeout, startIndex)
Console.WriteLine(isMatch)
```
6. 检查字符串的某个子串是否与正则表达式匹配,返回布尔值,并设置匹配选项、超时时间和输入字符串范围。
```
Dim str As String = "This Is A Test"
Dim pattern As String = "test"
Dim startIndex As Integer = 10
Dim options As RegexOptions = RegexOptions.IgnoreCase
Dim timeout As TimeSpan = TimeSpan.FromSeconds(1)
Dim inputLength As Integer = str.Length - startIndex
Dim isMatch As Boolean = Regex.IsMatch(str, pattern, options, timeout, inputLength, startIndex)
Console.WriteLine(isMatch)
```
7. 检查字符数组中的某个子串是否与正则表达式匹配,返回布尔值。
```
Dim chars() As Char = {"T"c, "h"c, "i"c, "s"c, " "c, "I"c, "s"c, " "c, "A"c, " "c, "T"c, "e"c, "s"c, "t"c}
Dim pattern As String = "test"
Dim isMatch As Boolean = Regex.IsMatch(chars, pattern)
Console.WriteLine(isMatch)
```
8. 检查字符数组中的某个子串是否与正则表达式匹配,返回布尔值,并设置匹配选项。
```
Dim chars() As Char = {"T"c, "H"c, "I"c, "S"c, " "c, "I"c, "S"c, " "c, "A"c, " "c, "T"c, "E"c, "S"c, "T"c}
Dim pattern As String = "test"
Dim options As RegexOptions = RegexOptions.IgnoreCase
Dim isMatch As Boolean = Regex.IsMatch(chars, pattern, options)
Console.WriteLine(isMatch)
```
9. 检查字符数组中的某个子串是否与正则表达式匹配,返回布尔值,并设置匹配选项、超时时间和输入字符数组范围。
```
Dim chars() As Char = {"T"c, "H"c, "I"c, "S"c, " "c, "I"c, "S"c, " "c, "A"c, " "c, "T"c, "E"c, "S"c, "T"c}
Dim pattern As String = "test"
Dim options As RegexOptions = RegexOptions.IgnoreCase
Dim timeout As TimeSpan = TimeSpan.FromSeconds(1)
Dim startIndex As Integer = 10
Dim length As Integer = chars.Length - startIndex
Dim isMatch As Boolean = Regex.IsMatch(chars, pattern, options, timeout, length, startIndex)
Console.WriteLine(isMatch)
```
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)